473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Validation not working for one dropdown option

Hi All,

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
  1. <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> 
Dec 3 '07 #1
2 1410
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

The reason it doesn't work is that you're validating author which is not defined for the DVD option.

Just a note: I'm assuming onKlick is in some other language?
Dec 3 '07 #2
acoder
16,027 Expert Mod 8TB
I've changed the thread title. Please use a good thread title. Thanks!
Dec 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
1
by: Obe | last post by:
PLEASE HELP! I'm writing a function to populate DropDownLists from and xml file. I am having a problem getting my XPathNavigator to select any nodes when I attach a schema to my xml document. ...
3
by: sewerized | last post by:
Hello all, I'm having a problem with a user preferences form I'm creating. I want to use dynamic dropdown SELECT boxes for this so my page doesn't get cluttered with 100000 links. Since I...
4
by: Gogo82 | last post by:
Hi, I need help with a dropdown menu. The deal is that I´ve got 2 menu´s, and I need to be able to pick one cathegory in each menu(menu1 and menu2) and press "submit" to get the info. How...
1
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first...
4
by: dkyadav80 | last post by:
hi sir, I have following code: {code} <html> <body> Name:<input type="text" name="n1" id="n1"> DOB: <select name="dd"><option value="date">date</option>
6
by: Zetten | last post by:
This is going to be a long one, but hopefully that will make it easier to understand. I know I don't like posts with too little detail when I'm searching for help. I am creating a form with which...
0
by: nitinsingh1 | last post by:
Hi, I am using a PDA containing Windows Mobile 5.0 for my client application in JAVA (JSP & SERVLET).There i am using a dropdown menu on a page.There are 3 different values (A,B,C) in that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.