timmah1 Posted May 4, 2009 Share Posted May 4, 2009 After replacing the < with <, my form no longer validates. Can anybody tell me why this is? My form tag <form action="quote.php" method="post" enctype="application/x-www-form-urlencoded" name="quote" onsubmit="return validate();"> Here is the code <script type="text/javascript"> function validate() { if (document.quote.first_name.value.length < 1) { alert("Please enter your first name."); return false; } if (document.quote.last_name.value.length < 1) { alert("Please enter your last name."); return false; } if (document.quote.email.value.length < 7) { alert("Please enter your email address."); return false; } if (document.quote.zip.value.length < 5) { alert("Please enter a 5 digit zip code."); return false; } if (document.quote.phone1.value.length < 3) { alert("Please enter a valid phone number."); return false; } if (document.quote.phone2.value.length < 3) { alert("Please enter a valid phone number."); return false; } if (document.quote.phone3.value.length < 4) { alert("Please enter a valid phone number."); return false; } if (document.quote.age.value.length < 2) { alert("Please enter your gender and age."); return false; } return true; } </script> Thank you in advance Link to comment https://forums.phpfreaks.com/topic/156818-solved-from-wont-validate/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Why did you change < to <? Link to comment https://forums.phpfreaks.com/topic/156818-solved-from-wont-validate/#findComment-825971 Share on other sites More sharing options...
timmah1 Posted May 4, 2009 Author Share Posted May 4, 2009 So that it would be validated http://validator.w3.org Without that, it would not validate Link to comment https://forums.phpfreaks.com/topic/156818-solved-from-wont-validate/#findComment-825990 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Can you put back the < symbol? Link to comment https://forums.phpfreaks.com/topic/156818-solved-from-wont-validate/#findComment-826017 Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 The reason it stopped working is because < is not valid javascript syntax. Try putting the <script> block into the <head> section of the page and see if it validates with the < symbol. Link to comment https://forums.phpfreaks.com/topic/156818-solved-from-wont-validate/#findComment-826045 Share on other sites More sharing options...
timmah1 Posted May 4, 2009 Author Share Posted May 4, 2009 It is in the head I fixed it putting comment tags in <script type="text/javascript"> <!-- function validate() { if (document.quote.first_name.value.length <1) { alert("Please enter your first name."); return false; } if (document.quote.last_name.value.length <1) { alert("Please enter your last name."); return false; } if (document.quote.email.value.length <7) { alert("Please enter your email address."); return false; } if (document.quote.zip.value.length <5) { alert("Please enter a 5 digit zip code."); return false; } if (document.quote.phone1.value.length <3) { alert("Please enter a valid phone number."); return false; } if (document.quote.phone2.value.length <3) { alert("Please enter a valid phone number."); return false; } if (document.quote.phone3.value.length <4) { alert("Please enter a valid phone number."); return false; } if (document.quote.age.value.length <2) { alert("Please enter your gender and age."); return false; } return true; } // --> </script> [/code Works perfect now! Thanks for all the help Link to comment https://forums.phpfreaks.com/topic/156818-solved-from-wont-validate/#findComment-826140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.