PDA

View Full Version : selected index of drop down...real easy?!


homerUK
12-22-2002, 10:47 AM
hey,

I have a real simple question that for some reason, I cant get it to work!! I have a drop down list on my page which looks like this:


<select name="TableBorderColor" id="TableBorderColor" class="textbox">
<option value="please select">please select</option>
<option value="none">None</option>
<option style="background-color:#FF0000">#FF0000</option>
<option style="background-color:#FFFF00">#FFFF00</option>
<option style="background-color:#00FF00">#00FF00</option>
.............
etc etc
............
<option style="background-color:#FFFAFA">#FFFAFA</option>
</select>


and in the JavaScript, I use the following to get the value:


borderColour = table.TableBorderColor[table.TableBorderColor.selectedIndex].text;


but for some reason it always comes up with an error "TableBorderColor.selectedIndex is null or not an object"

any ideas what I'm doing wrong?!

thanks....!!

Borgtex
12-22-2002, 10:58 AM
table.TableBorderColor.selectedIndex

It works for me in IE; considering that "table" is the name of the form wich contains the dropdown, not a reference to a real table

homerUK
12-22-2002, 12:48 PM
hey... I tried the code on it's own (away from the other code) and it worked fine.... after much searching I realised that I had called a variable "table" earlier on.... so I think the JS was trying to get the properties of the variable table, rather than the actual FORM part of it!!

stupid!!

:rolleyes: