Guest User

Untitled

a guest
Oct 5th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>register</title>
  4. <script type="text/javascript">
  5. function id(id){
  6. return document.getElementById(id);
  7. }
  8. function setCookie(c_name,value,expiredays){
  9. var exdate=new Date();
  10. exdate.setDate(exdate.getDate()+expiredays);
  11. document.cookie=c_name+ "=" +escape(value)+
  12. ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
  13. }
  14. function checkpw(form){
  15. if(form.password.value != form.chkpasswd.value){
  16. id("note3").textContent="password and checkpassword not same";
  17. form.username.focus();
  18. return;
  19. }
  20. else
  21. id("note3").textContent="";
  22. }
  23. function register(form){
  24. if(form.username.value == ""){
  25. id("note1").textContent="please enter the username";
  26. form.username.focus();
  27. return;
  28. }
  29. else
  30. id("note1").textContent="";
  31. if(form.password.value == ""){
  32. id("note2").textContent="please enter the password";
  33. form.password.focus();
  34. return;
  35. }
  36. else
  37. id("note1").textContent="";
  38.  
  39. var ajax=new XMLHttpRequest();
  40. ajax.onreadystatechange = function(){
  41. if(this.readyState == 4 && this.status ==200){
  42. var check = this.responseText;
  43. if(check == "true"){
  44. setCookie('username',form.username.value,10);
  45. alert("success");
  46. location.replace("index.html");
  47. }
  48. else if(check == "same"){
  49. id("check").textContent="this id has been used";
  50. return;
  51. }
  52. else if(check == "false"){
  53. id("check").textContent="wrong username or password";
  54. return;
  55. }
  56. else{
  57. id("check").textContent=check;
  58. return;
  59. }
  60. }
  61. }
  62. ajax.open("POST","register.php");
  63. ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  64. ajax.send("username="+form.username.value+"&password="+form.password.value);
  65. }
  66. </script>
  67. </head>
  68. <body>
  69. <form>
  70. <fieldset>
  71. <legend>register</legend>
  72. username:<input type="text" name="username" /><sapn id="note1"></sapn><br />
  73. password:<input type="password" name="password" value=""/><span id="note2"></span><br />
  74. checkpassword:<input type="password" name="chkpasswd" value="" onblur="checkpw(this.form)" /><span id="note3"></span><br />
  75. <input type="button" value="sent" onclick="register(this.form)" />
  76. <p id="check"></p>
  77. </fieldset>
  78. </form>
  79. <a href="login.html">Back</a>
  80. <a href="index.html">index</a>
  81. </body>
  82. </html>
Add Comment
Please, Sign In to add comment