16. januar 2003 - 15:17Der er
9 kommentarer og 1 løsning
Validering af checkbox
Hej!
Nedenstående kode validerer indholdet i udvalgte felter i en formular. Formularen indeholder også en checkbox (Terms), men jeg kan ikke få scriptet til at validere om den er checked eller unchecked.
Løsningsforslag modtages!
På forhånd tak / Chr.
Start på min kode ----------------------------------------------------- <script language="JavaScript"><!-- function check() { if(form1.Advert.value == '') { alert("Please fill in the \"Chosen advert\" field"); form1.Advert.focus(); return false; } if(form1.Media.value == '') { alert("Please fill in the \"Advert to appear in\" field"); form1.Media.focus(); return false; } if(form1.Publication.value == '') { alert("Please fill in the \"Publication month and year\" field"); form1.Publication.focus(); return false; } if(form1.Sizewidth.value == '') { alert("Please fill in the \"Size of advert in mm - width\" field"); form1.Sizewidth.focus(); return false; } if(form1.Sizeheight.value == '') { alert("Please fill in the \"Size of height in mm - height\" field"); form1.Sizeheight.focus(); return false; } if(form1.Deadline.value == '') { alert("Please fill in the \"Deadline\" field"); form1.Deadline.focus(); return false; } if(form1.Contactperson.value == '') { alert("Please fill in the \"Name of contact person\" field"); form1.Contactperson.focus(); return false; } if(form1.Telephonecontact.value == '') { alert("Please fill in the \"Telephone number\" field"); form1.Telephonecontact.focus(); return false; } if(form1.Emailcontact.value == '') { alert("Please fill in the \"E-mail address\" field"); form1.Emailcontact.focus(); return false; } if(form1.Emailapproval.value == '') { alert("Please fill in the \"E-mail address\" field"); form1.Emailapproval.focus(); return false; } if(form1.Attachment.value == '') { alert("Please fill in the \"Attach your text file\" field"); form1.Attachment.focus(); return false; } if(form1.Name.value == '') { alert("Please fill in the \"Name\" field"); form1.Name.focus(); return false; } if(form1.Company.value == '') { alert("Please fill in the \"Company\" field"); form1.Company.focus(); return false; } if(form1.Addressorder.value == '') { alert("Please fill in the \"Address\" field"); form1.Addressorder.focus(); return false; } if(form1.Postalcode.value == '') { alert("Please fill in the \"Postal code\" field"); form1.Postalcode.focus(); return false; } if(form1.City.value == '') { alert("Please fill in the \"City\" field"); form1.City.focus(); return false; } if(form1.Country.value == '') { alert("Please fill in the \"Country\" field"); form1.Country.focus(); return false; } if(form1.Telephoneorder.value == '') { alert("Please fill in the \"Telephone number\" field"); form1.Telephoneorder.focus(); return false; } if(form1.Emailorder.value == '') { alert("Please fill in the \"E-mail address\" field"); form1.Emailorder.focus(); return false; } if(form1.Terms.field.checked == '') { alert("Please check \"Terms and conditions\" box"); form1.Terms.focus(); return false; } } // --> </script> ------------------------------------- Slut på min kode
<script language="JavaScript"><!-- function check() { if(form1.Advert.value == '') { alert("Please fill in the \"Chosen advert\" field"); form1.Advert.focus(); return false; } if(form1.Media.value == '') { alert("Please fill in the \"Advert to appear in\" field"); form1.Media.focus(); return false; } if(form1.Publication.value == '') { alert("Please fill in the \"Publication month and year\" field"); form1.Publication.focus(); return false; } if(form1.Sizewidth.value == '') { alert("Please fill in the \"Size of advert in mm - width\" field"); form1.Sizewidth.focus(); return false; } if(form1.Sizeheight.value == '') { alert("Please fill in the \"Size of height in mm - height\" field"); form1.Sizeheight.focus(); return false; } if(form1.Deadline.value == '') { alert("Please fill in the \"Deadline\" field"); form1.Deadline.focus(); return false; } if(form1.Contactperson.value == '') { alert("Please fill in the \"Name of contact person\" field"); form1.Contactperson.focus(); return false; } if(form1.Telephonecontact.value == '') { alert("Please fill in the \"Telephone number\" field"); form1.Telephonecontact.focus(); return false; } if(form1.Emailcontact.value == '') { alert("Please fill in the \"E-mail address\" field"); form1.Emailcontact.focus(); return false; } if(form1.Emailapproval.value == '') { alert("Please fill in the \"E-mail address\" field"); form1.Emailapproval.focus(); return false; } if(form1.Attachment.value == '') { alert("Please fill in the \"Attach your text file\" field"); form1.Attachment.focus(); return false; } if(form1.Name.value == '') { alert("Please fill in the \"Name\" field"); form1.Name.focus(); return false; } if(form1.Company.value == '') { alert("Please fill in the \"Company\" field"); form1.Company.focus(); return false; } if(form1.Addressorder.value == '') { alert("Please fill in the \"Address\" field"); form1.Addressorder.focus(); return false; } if(form1.Postalcode.value == '') { alert("Please fill in the \"Postal code\" field"); form1.Postalcode.focus(); return false; } if(form1.City.value == '') { alert("Please fill in the \"City\" field"); form1.City.focus(); return false; } if(form1.Country.value == '') { alert("Please fill in the \"Country\" field"); form1.Country.focus(); return false; } if(form1.Telephoneorder.value == '') { alert("Please fill in the \"Telephone number\" field"); form1.Telephoneorder.focus(); return false; } if(form1.Emailorder.value == '') { alert("Please fill in the \"E-mail address\" field"); form1.Emailorder.focus(); return false; } if(document.form1.Terms.checked) { alert("Please check \"Terms and conditions\" box"); form1.Terms.focus(); return false; } } // --> </script>
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.