Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function login(){
  2.   var xmlhttp;
  3.   if (window.XMLHttpRequest) {
  4.     xmlhttp = new XMLHttpRequest();
  5.   } else {
  6.     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  7.   }
  8.  
  9.   xmlhttp.onreadystatechange = function () {
  10.     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  11.       // TODO: 3. If the response text is "invalidUserNamePassword", then we should notify
  12.       //          the user by replacing the innerHTML of <div id="loginError"> element with
  13.       //          "<h3>Invalid user name or password.</h3>".
  14.       if (xmlhttp.responseText === "invalidUserNamePassword"){
  15.           document.getElementById("loginError").innerHTML="<h3>Invalid user name or password.</h3>";
  16.       }
  17.        // TODO: 4. If the reponse text is not "invalidUserNamePassword", then the login is successful.
  18.       //          We should replace the innerHTML of <div id="content"> element with responseText.
  19.      
  20.     if(xmlhttp.responseText ==="invalidUserNamePassword"){
  21.         document.getElementById("content").innerHTML=xmlhttp.responseText; 
  22.     }
  23.     }
  24.   }
  25.  
  26.   // TODO: 1. Retrieve the input user name and password from the
  27.   //          input elements with id "loginUserName" and "loginPassword".
  28.     var userName = document.getElementById("loginUserName");
  29.     var pw = document.getElementById("loginPassword");
  30.    
  31.  
  32.   // TODO: 2. Send an HTTP GET request to retrieve handleLogin.php, which should carry 2
  33.   //          key-value pairs corresponding to "userName" and "password".
  34.     xmlhttp.open("GET","handleLogin.php?userName="+$_GET["userName"] "&password="+$_GET["pw"],true);
  35.     xmlhttp.send();
  36. }
  37.  
  38. function updateProfile(){
  39.  
  40.   // TODO: 1. Retrive the nick name, gender and brief introduction
  41.   //          from the input elements with id "nickNameInputBox",
  42.   //          "genderInputBox" and "briefIntroInputBox", repectively.
  43.  
  44.   var nickName = document.getElementById("nickNameInputBox");
  45.   var gender = document.getElementById("genderInputBox");
  46.   var briefIntro = document.getElementById("briefIntroInputBox");
  47.  
  48.   var xmlhttp;
  49.   if (window.XMLHttpRequest) {
  50.     xmlhttp = new XMLHttpRequest();
  51.   } else {
  52.     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  53.   }
  54.  
  55.   xmlhttp.onreadystatechange = function () {
  56.     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  57.       // TODO: 3. Replace the innerHTML of the <h3 id="heading"> element
  58.       //          with responseText. Then set a "style" attribute
  59.       //          in the <h3 id="heading"> element with value of "color:red;".
  60.       //                Hint: use "setAttribute()" http://www.w3schools.com/jsref/met_element_setattribute.asp
  61.       document.getElementById("heading").getElementsByTagName("h3").innerHTML=xmlhttp.responseText;
  62.       document.getElementById("heading").getElementsByTagName("h3").setAttribute("style", "color: red;");
  63.     }
  64.   }
  65.  
  66.  
  67.   // TODO: 2. Generate the HTTP GET request, carrying 3 key-value pairs corresponding to
  68.   //          "nickName", "gender" and "briefIntro"
  69.   xmlhttp.open("GET","handleLogin.php?nickName="+nickName.value "&gender="+gender.value"&briefIntro="+briefIntro.value,true);
  70.   xmlhttp.send();
  71. }
  72.  
  73. function inputCheck(){
  74.  
  75.   // TODO: Check the input gender value in the input element with ID "genderInputBox":
  76.   //       if the input value is not "F" nor "M" nor "", show an alert box with the message "Gender should be either F or M"
  77.   //         and refocus the cursor on the gender input box
  78.   if(document.getElementById("genderInputBox").value !== "F" && document.getElementById("genderInputBox").value !=="M" && document.getElementById("genderInputBox").value !=="" ){
  79.       alert("Gender should be either F or M");
  80.     alert("Gender should be either F or M");
  81.     document.getElementById('genderInputBox').focus();
  82.  
  83.   }
  84.  
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement