Form Registrazione Maratona


/ Published in: JavaScript
Save to your folder(s)

Javascript


Copy this code and paste it in your HTML
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>Documento senza titolo</title>
  5. <link href="css/style.css" rel="stylesheet" type="text/css"/>
  6.  
  7. <link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
  8.  
  9. </head>
  10.  
  11. <body>
  12. <form name="formMaratona" id="formMaratona">
  13. <h2>MODULO DI ISCRIZIONE GARA DI CICLISMO "MORETTI" 2016</h2>
  14. <div id="nome">
  15. <p>NOME</p>
  16. <input type="text" id="textNOME" />
  17. <br>
  18. </div>
  19. <div id="cognome">
  20. <p>COGNOME</p>
  21. <input type="text" id="textCOGNOME" />
  22. <br>
  23. </div>
  24. <div id="email">
  25. <p>E-MAIL</p>
  26. <input type="text" id="textEMAIL" />
  27. <br>
  28. </div>
  29. <div id="password">
  30. <p>PASSWORD</p>
  31. <input type="text" id="textPASSWORD" />
  32. <br>
  33. </div>
  34. <div id="confermapassword">
  35. <p>CONFERMA PASSWORD</p>
  36. <input type="text" id="textCONFERMAPASSWORD" />
  37. <br>
  38. </div>
  39. <p>KILOMETRAGGIO DELLA GARA</p>
  40. <select id="selectKilometraggio">
  41. <option value="-1" selected="selected">Seleziona il kilometraggio</option>
  42. <option value="1">12 KM</option>
  43. <option value="2">24 KM</option>
  44. <option value="3">30 KM</option>
  45. <option value="4">50 KM</option>
  46. </select>
  47. <br>
  48. <p>DESIDERI IL PRANZO AL SACCO DI FINE GARA?</p>
  49. <label>
  50. <input type="radio" name="PranzoSacco" value="si" id="Si" />
  51. Si</label>
  52. <br />
  53. <label>
  54. <input type="radio" name="PranzoSacco" value="no" id="No" />
  55. No</label>
  56. <br>
  57. <div id="privacy">
  58. <input type="checkbox" id="checkboxPrivacy" />
  59. <label for="checkbox">Ho letto e accetto l'informativa sulla Privacy</label>
  60. <br>
  61. </div>
  62. <input type="button" name="INVIA" id="INVIA" value="INVIA" onClick="invia()"/>
  63. <input type="reset" name="buttonClear" id="buttonClear" value="PULISCI" />
  64.  
  65. </form>
  66. <script>
  67. function invia ()
  68. {
  69.  
  70. messaggioErrore="ABBIAMO RILEVATO I SEGUENTI ERRORI:";
  71. messaggioOk="MESSAGGIO INVIATO";
  72.  
  73. nome=document.formMaratona.textNOME.value;
  74. cognome=document.formMaratona.textCOGNOME.value;
  75. email=document.formMaratona.textEMAIL.value;
  76. indiceChiocciola=document.formMaratona.textEMAIL.value.indexOf("@");
  77. indicePunto=document.formMaratona.textEMAIL.value.indexOf(".");
  78. indiceSpazio=document.formMaratona.textEMAIL.value.indexOf(" ");
  79. password=document.formMaratona.textPASSWORD.value;
  80. confermaPassword=document.formMaratona.textCONFERMAPASSWORD.value;
  81. indice=document.formMaratona.selectKilometraggio.selectedIndex;
  82. privacy=document.formMaratona.checkboxPrivacy.checked;
  83. si=document.formMaratona.Si.checked;
  84. no=document.formMaratona.No.checked;
  85.  
  86.  
  87. errore=false;
  88.  
  89.  
  90. if(nome=="")
  91. {errore=true;
  92. messaggioErrore=messaggioErrore+"\n NOME è un campo obbligatorio; ";}
  93.  
  94. if(cognome=="")
  95. {errore=true;
  96. messaggioErrore=messaggioErrore+"\n COGNOME è un campo obbligatorio; ";}
  97.  
  98. if((email=="") || (email.length<6) || (indiceChiocciola==-1) || (indicePunto==-1) || (indicePunto<indiceChiocciola) || (indiceSpazio!=-1))
  99. {errore=true;
  100. messaggioErrore=messaggioErrore+"\n E-MAIL è un campo obbligatorio e l'indirizzo inserito deve essere valido; ";}
  101.  
  102. if ((password=="") || (password.length<8))
  103. {errore=true;
  104. messaggioErrore=messaggioErrore+"\n PASSWORD è un campo obbligatorio e deve contenere almeno 8 ccaratteri; ";}
  105.  
  106. if (confermaPassword!=password)
  107. {errore=true;
  108. messaggioErrore=messaggioErrore+"\n CONFERMA PASSWORD deve essere uguale a PASSWORD; ";}
  109.  
  110. if (indice==0)
  111. {errore=true;
  112. messaggioErrore=messaggioErrore+"\n Seleziona il kilometraggio per il quale desideri gareggiare; ";}
  113.  
  114. if((si==false) && (no==false))
  115. {errore=true;
  116. messaggioErrore=messaggioErrore+"\n Devi esprimere una preferenza sul pranzo al sacco;";}
  117.  
  118. if(privacy==false)
  119. {errore=true;
  120. messaggioErrore=messaggioErrore+"\n Devi leggere e accettare l'informativa sulla privacy";}
  121.  
  122. if(errore==true)
  123. {alert(messaggioErrore);}
  124. else
  125. {alert(messaggioOk);}
  126. }
  127.  
  128. </script>
  129. </body>
  130. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.