I have spent a long time on this and still cant figure out whats wrong. I have recently started with javscript and my question is as follows:
The page works fine but if the User selects DVD from the dropdown and doesnt type anything in the 2 text fields, it should display an alert. Its working fine for the other options in the drop down, only this does not work.
Would greatly appreciate if someone can enlighten me on this... thanks.
Expand|Select|Wrap|Line Numbers
- <html><head><script type="text/javascript"> function clickfunction() { if (search.searchtype.value=="books") { document.getElementById("stuffHere").innerHTML = "Book Title : "; document.getElementById("stuffHere2").innerHTML = "<input type=text name=title size=30>"; document.getElementById("stuffHere3").innerHTML = "Author : "; document.getElementById("stuffHere4").innerHTML = "<input type=text name=author size=30>"; } else if (search.searchtype.value=="audio") { document.getElementById("stuffHere").innerHTML = "Book Title : "; document.getElementById("stuffHere2").innerHTML = "<input type=text name=title size=30>"; document.getElementById("stuffHere3").innerHTML = "Author : "; document.getElementById("stuffHere4").innerHTML = "<input type=text name=author size=30>"; } else if (search.searchtype.value=="dvd") { document.getElementById("stuffHere").innerHTML = "DVD Title : "; document.getElementById("stuffHere2").innerHTML = "<input type=text name=title size=30>"; document.getElementById("stuffHere3").innerHTML = "Year : "; document.getElementById("stuffHere4").innerHTML = "<input type=text name=year size=10 maxlength=4>"; } } function validate_required(field1,field2){if ((field1.value==null||field1.value=="")&&(field2.value==null||field2.value=="")) {return false;}else {return true;}} function validate_form(thisform){with (thisform){if (validate_required(title,author)==false) {alert("Please type the Book Title or Name of the Author you want to search!"); title.focus(); return false; }else if (validate_required(title,year)==false) {alert("Please type the DVD Title or Year of Release you want to Search"); title.focus(); return false; } }} </script></head><body background="pink_fabric.gif"><span style="color urple;"><font color="purple" size="5"><br>Search for Books, Audio CDs and DVDs</font><br><br><FORM ACTION="" name=search METHOD=POST onsubmit="return validate_form(this)"><table><tr><td><font color="purple" size="">Search For :</font><td><select name="searchtype" size="1" onKlick="clickfunction()"> <option selected value="none">None</option> <option value="books">Books</option> <option value="audio">Audio CDs (Audio books)</option> <option value="dvd">DVDs</option> </select></td><td><INPUT TYPE=SUBMIT name=search VALUE="Search"></td></tr> <tr><td id="stuffHere" style="color urple"></td><td id="stuffHere2"></td></tr><tr><td id="stuffHere3" style="color urple"></td><td id="stuffHere4"></td></tr> </table></FORM></font></span></body></html>