PDA

View Full Version : selectedindex problem


egrodsky
05-10-2003, 10:37 PM
I have coded a simple list of 4 choices as follows:
<td width="100" valign="top" rowspan="4" height="88">
<select name="csvalidate" size="4">
<option>HTML
<option>CSS
<option>CGI
<option>JavaScript
</select>
</td>

In a function I placed the following:
item_index = document.order.csvalidate.selectedIndex;
if (item_index = 3) .....

The problem I am having is that I cannot get item_index to be evaluated correctly. It doesn't appear to obtain the value that it should. I have checked documentation everywhere and I appear to be following what should be done.

Any comments are greatly appreciated,

TIA,

Ed

liorean
05-10-2003, 10:50 PM
What value does it give as you use it currently? (undefined, one lower that expected, NaN, null, anything else?)

What if you try to use the document.forms, form.elements and select.options collections?

egrodsky
05-10-2003, 11:26 PM
I get a zero.

All I need to do is just obtain a value from a list. Can't find any good documentation on this. The ones I did find indicate that what I am doing is correct.

Thanks,

Ed

liorean
05-10-2003, 11:42 PM
A zero indicates that the first item is selected (as it is by default). Did it output 0 when you selected another option?

(Remember that JavaScript, like most programming languages, counts from 0, not 1.)

PauletteB
05-11-2003, 01:49 AM
Try with:

<option value="HTML">HTML
<option value="CSS">CSS

cheesebagpipe
05-11-2003, 02:30 AM
if (item_index == 3)