Guest User

Untitled

a guest
Apr 3rd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. My HTML CODE:
  2.  
  3. <body>
  4. <div>
  5. <center>
  6. <form action="Javascript:void(0);"method="post" onsubmit="subm();">
  7. <label for="fname">First Name:</label>&emsp;
  8. <input type="text" id="fname" />
  9. <br/>
  10. <label for="lname">Last Name:</label>&emsp;
  11. <input type="text" id="lname" />
  12. <br/>
  13. <label for="uname">User Name:</label>&emsp;
  14. <input type="text" id="uname" />
  15. <br/>
  16. <label for="pass">Password:</label>&emsp;&ensp;&nbsp;
  17. <input type="text" id="pass" />
  18. <br/>
  19. <label for="dob">Date of Birth:</label>&emsp;&emsp;&nbsp;
  20. <input type="date" id="dob" />
  21. <br/>
  22. <label>Age:</label>&emsp;&emsp;&emsp;&emsp;&emsp;
  23. <input type="text" id="age" />
  24. <br/>
  25. <span>Gender:</span>&emsp;&emsp;&emsp;&emsp;&ensp;
  26. <input type="radio" name="gender" id="male" />
  27. <label for="male">Male</label>
  28. <input type="radio" name="gender" id="female" />
  29. <label for="female">Female</label>
  30. <br/>
  31. <p>For what purpose(s) you are making account?</p>
  32. <input type="checkbox" id="app" name="purpose" value="storingapps" />
  33. <label for="app">Storing Apps</label>
  34. <input type="checkbox" id="site" name="purpose" value="storingsites" />
  35. <label for="site">Storing Sites</label>
  36. <input type="checkbox" id="fun" name="purpose" value="fun" />
  37. <label for="fun">Fun</label>
  38. <br/>
  39. <input type="submit" value="Submit" class="button" />
  40. </form>
  41. </center>
  42. </div>
  43.  
  44. MY JS CODE:
  45.  
  46. <script>
  47. var labelsarray = document.getElementsByTagName("label");
  48. var inputsarray = document.getElementsByTagName("input");
  49. var array = [];
  50. function subm() {
  51. var users = {
  52. FirstName: inputsarray[0].value,
  53. LastName: inputsarray[1].value,
  54. UserName: inputsarray[2].value,
  55. Password:  inputsarray[3].value,
  56. DateofBirth: inputsarray[4].value,
  57. Age: inputsarray[5].value,
  58. Purpose: ""
  59. };
  60. if (inputsarray[6].checked === true) {
  61. users.Gender = "Male";
  62. }
  63. else if (inputsarray[7].checked === true) {
  64. users.Gender = "Female";
  65. }
  66. if (inputsarray[8].checked === true) {
  67. users.Purpose += " Storing Apps";
  68. }
  69. if (inputsarray[9].checked === true) {
  70. users.Purpose += " Storing Sites";
  71. }
  72. if (inputsarray[10].checked === true) {
  73. users.Purpose += " Fun";
  74. }
  75. array.push(users);
  76. for (var i=0;i<array.length;i++) {
  77. localStorage.setItem("User Data: ", JSON.stringify(array[i]));
  78. }
  79. }
  80. </script>
Add Comment
Please, Sign In to add comment