Hi!
I am creating a basic form with validation and storing a cookie for 6 months. I managed majority of it but don't know where I'm going wrong.
Any help is appreciated!
My code so far is:
Code:<html> <head> <script type="text/javascript"> //validate the form (name shouldn't be blank) function validate() { if (document.myform.Name.value=="" || null ) { alert("Please enter your name"); return false; if (document.myform.Name.value !=="" || null ) return true; } //If a name is entered then the value will be set to true.// var email=document.myform.Email.value; var at=email.indexOf("@"); var dot=email.lastIndexOf("."); if (at<1 || dot<at+2 || dot+2>=email.length) { alert("Please enter a valid e-mail address"); return false; } var dob = document.myform.DateOfBirth.value; var val = /^\d{2}\/\d{2}\/\d{4}$/; if (!val.test(dob)) {alert("Please enter a valid date of birth"); return false;} } function Cookie() { var x = new Date(); x.setMonth( x.getMonth() + 6 ); namecookie= escape(document.myform.Name.value) + "" / document.cookie= name + "=" + namecookie + "; expires=" +x.toGMTString() + ";" if(document.cookie) { alert("A cookie has been created with the name " + document.cookie + " and it will expire on " + x.toGMTString()); } } </script> <FORM METHOD="get" NAME="myform" onsubmit=""> <!--create text fields/tickbox--> Name: <br><input type="text" name="Name" value="" size="30" maxlength="50" /> <br><br> Email: <br><input type="text" name="Email" value="" size="30" maxlength="50" /> <br><br> Gender: <br><input type="text" name="Gender" size="30" maxlength="6"> <br><br> Date Of Birth (DD/MM/YYYY): <br><input type="text" name="DateOfBirth" size="30" maxlength="10"> <br><br> Please tick the box if you would like to be contacted for other marketing purposes. <INPUT TYPE="checkbox" NAME="check" VALUE="Tick"> <br><br> <input type="submit" value="Sign Up" onclick="validate(this.form); Cookie();"/> <!--submit button--> </html>
At the moment I'm only wanting to store the cookie for 6 months nothing else, can anyone help me?


Reply With Quote

Bookmarks