mariocesar Posted January 11, 2008 Share Posted January 11, 2008 Hi, this form is working fine when the user don' fill the field the script promts them to do it works fine, how can I make the user fill "other" when they chosse other in the drop down menu, here is the script and the form } function validate(form) { if (form.AdSource.value.length == 0) { alert("Please enter how did you hear about Us?.") form.AdSource.focus() return false } } this is the form <tr><td colspan="2"><P><font color="#FF0000">*</font><FONT color=#3366cc>How did you hear about us?</FONT> <SELECT name="AdSource" id="AdSource"> <OPTION selected>Select</OPTION> <OPTION value=Google>Google</OPTION> <OPTION value=Yahoo>Yahoo</OPTION> <OPTION value=MSN>MSN</OPTION> <OPTION value=MSN>Intelecard Magazine</OPTION> <OPTION value=MSN>The Prepaid Press</OPTION> <OPTION value=MSN>Direct Magazine</OPTION> <OPTION value=Other>Other</OPTION> </SELECT> <INPUT class=mednavtext maxLength=36 size=24 value="Type other here." name="OtherSource"></P></td></tr> thanks in advance. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 12, 2008 Share Posted January 12, 2008 Here is something along the lines of what your were doing: <script language="javascript"> function validate(form) { var txtamount = document.myform.AdSource.value; if (txtamount == "Other") { alert("Please enter how did you hear about Us?."); document.myform.Other_Source.focus(); return false; } } </script> <form name="myform"> <table> <tr><td colspan="2"><P><font color="#FF0000">*</font><FONT color=#3366cc>How did you hear about us?</FONT> <SELECT name="AdSource" id="AdSource" onchange="validate(this.value)"> <OPTION selected>Select</OPTION> <OPTION value=Google>Google</OPTION> <OPTION value=Yahoo>Yahoo</OPTION> <OPTION value=MSN>MSN</OPTION> <OPTION value=MSN>Intelecard Magazine</OPTION> <OPTION value=MSN>The Prepaid Press</OPTION> <OPTION value=MSN>Direct Magazine</OPTION> <OPTION value=Other>Other</OPTION> </SELECT> <INPUT class=mednavtext maxLength=36 size=24 value="Type other here." name="Other_Source"></P></td></tr> </table> </form> But you can also validate the text field too make it completely accurate. Your on the right track; by checking the input value length. Check out these tutorials to do see how to do this: http://www.google.com/search?hl=en&q=Form+Validation&btnG=Google+Search Quote Link to comment Share on other sites More sharing options...
mariocesar Posted January 13, 2008 Author Share Posted January 13, 2008 The script is working but when you fill the text field keeps showing the message (how did you hear about us?) this validation is working fine the only thing I want to add is when the visitor choose "other" from the drop down menu, to make them fill the text box "type other here", here is the original code: <script language="javascript"> function validate(form) { if (form.Name.value.length == 0) { alert("Please enter your name.") form.Name.focus() return false } if (form.Address.value.length == 0) { alert("Please enter your Address.") form.Address.focus() return false } if (form.City.value.length == 0) { alert("Please select your City.") form.City.focus() return false } if (form.State.value.length == 0) { alert("Please select your State.") form.State.focus() return false } if (form.Zip.value.length == 0) { alert("Please select your Zip.") form.Zip.focus() return false } if (form.Phonenumber.value.length == 0) { alert("Please enter your phone number, with area code.") form.Phonenumber.focus() return false } if (form.email.value.length == 0) { alert("Please enter your e-mail address.") form.email.focus() return false } if (form.email.value.indexOf("@") == -1) { alert("Please enter a valid e-mail address."); form.email.focus(); return false; } if (form.AdSource.value.length == 0) { alert("Please enter how did you hear about Us?.") form.AdSource.focus() return false } } and here is the part of the form where the text " type other here" suppose to be fill, thanks. <FORM ENCTYPE="multipart/form-data" method="POST" action="contacton.php" name="form" > <tr><td colspan="2"><P><font color="#FF0000">*</font><FONT color=#3366cc>How did you hear about us?</FONT> <SELECT name="AdSource" id="AdSource"> <OPTION selected>Select</OPTION> <OPTION value=Google>Google</OPTION> <OPTION value=Yahoo>Yahoo</OPTION> <OPTION value=MSN>MSN</OPTION> <OPTION value=Intelecard Magazine>Intelecard Magazine</OPTION> <OPTION value=The Prepaid Press>The Prepaid Press</OPTION> <OPTION value=Direct Magazine>Direct Magazine</OPTION> <OPTION value=American Printer>American Printer</OPTION> <OPTION value=Print Professional>Print Professional</OPTION> <OPTION value=Printing Impressions>Printing Impressions</OPTION> <OPTION value=Other>Other</OPTION> </SELECT> <INPUT class=mednavtext maxLength=36 size=24 value="Type other here." name="OtherSource"></P></td></tr></form> Thank you. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 13, 2008 Share Posted January 13, 2008 But you can also validate the text field too make it completely accurate. Your on the right track; by checking the input value length. Check out these tutorials to do see how to do this: http://www.google.com/search?hl=en&q=Form+Validation&btnG=Google+Search That is why I said this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.