[thelist] JavaScript: Find matching number in list

Christian Heilmann codepo8 at gmail.com
Thu May 12 07:19:04 CDT 2005


> Howdy!
> 
> I have 3 drop down menus and each item in the menu is assigned a number.
> After the user selects an option in each of the 3 drop downs, I need to
> concatenate those together and then compare that string to a list of 3 digit
> strings to see if there is a match in the list. If there isn't, bark at
> them, if there is submit the form.
> 
> I am a newb in JS so I am looking at advice or examples that can help me
> out.

You get the current value of a select by checking its options,
specifically the selectedIndex one.

So if your selects are 
<select id="se1" name="se1"> 
<select id="se2" name="se2"> 
<select id="se2" name="se2">
 
you concatenate by 

var s1=document.getElementById('se1');
var s2=document.getElementById('se2');
var s3=document.getElementById('se3');
var con=s1.options[s1.selectedIndex].value+s2.options[s2.selectedIndex].value+s3.options[s3.selectedIndex].value;

then you compare con to your list and allow the form to be sent if
there is a value matching it.

--
Chris Heilmann 
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/  
Binaries: http://www.onlinetools.org/


More information about the thelist mailing list