Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selectedIndex - different behaviour in IE7 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi there,

I am using selectedIndex to reset a drop-down box to display its' first element using the code below. In FF it resets the drop-down to correctly display "Select an operation..." (position 0) but in IE7 it sets the drop-down to display "Insert" (position 1).
Code:
formElement.selectedIndex = 0;

Incidentally, the HTML used to build the drop-down is as follows:
Code:
<select id="operation">
  <option>Select an operation...</option>
  <option value="insert">Insert</option>
  <option value="edit">Edit</option>
</select>

Does anyone know how to get IE7 to behave itself?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Clive, nothing has changed in IE7 concerning the selectedIndex property of dropdown boxes. I took your example and pasted it into a new .html file and it ran fine. Here's the test I ran:
Code:
<select id="operation">
  <option>Select an operation...</option>
  <option value="insert">Insert</option>
  <option value="edit" selected="selected">Edit</option>
</select>

<input type="button" value="set to first element" onclick="document.getElementById('operation').selectedIndex = 0" />

I'm guessing that there's something else in your code that is causing the problem. Can you post more code or do you have a link to the site with the problem?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Hmm ... not sure why. This is just a guess -try assigning a value to the first option.
 
kaht,

I should have tried isolating the problem as you did because it works fine in IE7 in isolation.

I scoured the surrounding code and there was nothing obvious to me that would have caused this problem - other than strange behaviour due to the 0th option not having a value (dkdude ;-)).

So, I put in value="" as the value of the 0th option and now it all works fine. The weird thing is, when I remove the value="" I can't seem to replicate the original problem I was experiencing! Strange!

Thanks for the help guys!

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Sounds like it wasn't the solution then [smile]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Well I only made the one change dkdude suggested and it seemed to fix it! Weird, huh?!

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top