PDA

View Full Version : SELECT drop down & IE7 problem


adamskii
02-13-2008, 04:57 PM
Hi, really confused by this so any help will be greatly appreciated...

code snippet:

document.formName.selectName.options[0].value

The above code returns the desired value in firefox, but IE7 returns blank!

document.formName.selectName.selectedIndex

This bit returns the correct number in both FF & IE7, but I just cant get the value of the selectedIndex in IE :mad:

Kor
02-13-2008, 07:14 PM
Not enough data. Can we see the entire code? Do you use name or id for the elements? Which is the event to trigger the function and how that function looks like?

adamskii
02-14-2008, 09:16 AM
ok, having run a few more test it turns out Im blonder than I thought.

<select name="selectName">
<option>option A</option>
<option>option B</option>
</select>

The problem was I hadnt defined the values for each option in the select list, instead believing that if a value wasnt present, the content between the select tags would be returned instead. It does in FF but not IE.

So this was required:

<select name="selectName">
<option value="option A">option A</option>
<option value="option B">option B</option>
</select>

Kor
02-14-2008, 09:49 AM
The problem was I hadnt defined the values for each option in the select list, instead believing that if a value wasnt present, the content between the select tags would be returned instead. It does in FF but not IE.

Your presumption was wrong. The option element has several properties, amongst which are value and text. They are different, so that the text can not substitute the value, in case the value is missing.


<select onchange="alert('value= '+this.options[this.selectedIndex].value+' | text= '+this.options[this.selectedIndex].text)">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>

On the other hand the forms elements must have a value property, otherwise what is to be send on submit?