Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Oppgave 1-3</title>
  5. <meta charset="utf-8">
  6.  
  7. <script>
  8. // Register all variables
  9. var username, password, passwordAgain, age;
  10. var tid = new Date();
  11.  
  12. window.onload = oppstart;
  13.  
  14. function getAge(elem) {
  15. var birthdate = Date.parse(elem.value)
  16.  
  17. //Date difference is in milliseconds...
  18. var dateDifference = Date.now() - birthdate
  19.  
  20. //...so we need to convert it to years
  21. return dateDifference / 1000 / 60 / 60 / 24 / 365
  22. }
  23.  
  24. function oppstart(){
  25. document.getElementById("btnRegister").onclick = visMelding;
  26. }
  27.  
  28. function visMelding(){
  29. // Set input variables
  30. username = document.querySelector("input[name='Username']")
  31. password = document.querySelector("input[name='Password']")
  32. passwordAgain = document.querySelector("input[name='Passwordagain']");
  33. age = document.querySelector("input[name='birthdate']")
  34.  
  35. // If username input has no value, return error message
  36. if (!username.value) {
  37. return alert("Du må fylle inn feltet for brukernavn");
  38. }
  39.  
  40. // If the password fields have no value, return error message
  41. if (!password.value || !passwordAgain.value) {
  42. return alert("Du må fylle inn passordfeltene");
  43. }
  44.  
  45. // If the password fields have a value, check if their given values are equal
  46. else if (password.value !== passwordAgain.value) {
  47. return alert("Passordet må være likt i begge felt");
  48. }
  49.  
  50. //If age is less than 18, return an error message
  51. if (getAge(age) < 18) {
  52. return alert("Du er ikke gammel nok")
  53. }
  54. }
  55.  
  56. alert("Du er nå registrert. Velkommen");
  57. }
  58. </script>
  59. <style>
  60. .addCSS {
  61. margin-bottom: 5px;
  62. padding:5px;
  63. }
  64. </style>
  65. </head>
  66. <body>
  67. <h1>Velkommen til registrering:</h1>
  68. <div class="container">
  69. <div class="addCSS">
  70. <label><b>Skriv inn brukernavn:</b></label><br/>
  71. <input type="text" placeholder="Skriv brukernavn" name="Username">
  72. </div>
  73. <div class="addCSS"">
  74. <label><b>Skrive inn passord:</b></label><br/>
  75. <input type="password" placeholder="Skriv passord" name="Password" min="5"><br/>
  76. </div>
  77. <div class="addCSS"">
  78. <label><b>Bekreft passord:</b></label><br/>
  79. <input type="password" placeholder="skriv passord på nytt" name="Passwordagain"><br/>
  80. </div>
  81. <div class="addCSS"">
  82. <label><b>Fødselsdag:</b></label><br/>
  83. <input type="number" placeholder="Skriv fødselsdato" name="birthdate">
  84. </div>
  85.  
  86. <p class="addCSS" type="checkbox" checked="checked"> Husk passord </p>
  87.  
  88. <div class="knapper addCSS">
  89. <button type="button" id="btnRegister">Trykk her for å registrere deg</button>
  90. <button type="button" id="btnCancel">Avbryt</button>
  91. </div>
  92. </div>
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement