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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does selectedIndex work in Netscape?

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
This works in IE but not in Netscape

document.forms[0].SelectName.selectedIndex = 12;

In Netscape, I can retreive the value of selectedIndex but I cannot set it.
 
This works for me in NS4.7
<head>
<script type=&quot;text/javascript&quot;>
function setList () {
document.forms[0].wl_cars.selectedIndex = 1;
}
</script>
</head>
<body text=&quot;#000000&quot; bgcolor=&quot;#ffffff&quot; onload=&quot;setList();&quot;>
<form>
<select name=wl_cars>
<option value=&quot;-&quot;>-Cars-
<option value=ford>Ford
<option value=chevy>Chevy
</select>
</form>
</body>
[/code] Hope this helps,
Jessica
[ponytails2]
 
This is the script I'm using. I cannot figure out this result and why it doesn't work in netscape

<script language=javascript>
document.forms[0].SelectName.selectedIndex = 13;
//Shows 13 in netscape/ie
alert(document.forms[0].SelectName.selectedIndex);
</script>

<script language=javascript>
//Shows 0 in netscape, 13 in ie
alert(document.forms[0].SelectName.selectedIndex);
</script>
 
Where are the alerts in relation to the SelectName object and to each other? Hope this helps,
Jessica
[ponytails2]
 
exactly as they are shown. they appear after the <select> tag and within the<body> and <form> tags.

Normally, I find the programmer is to blame for most errors but in this case I think it might be netscape, especially since it works fine in ie
 
Hmmmm...I tried to simulate what you describe here:

It seems ok in Netscape 4.7, but I don't have any later versions to test with. Both alerts display 1.
Code:
<html>
<head>
<title></title>
<script type=&quot;text/javascript&quot;>

<!--
function doThis() {
  var cars = eval(&quot;document.forms[0].wl_cars&quot;);
  var car = cars.value;
  var colors = eval(&quot;document.forms[0].wl_colors&quot;);
  var color = colors.options[colors.selectedIndex].value;
  if (car == &quot;-&quot; || color == &quot;-&quot;) {
    cars.options[0].selected = true;
    colors.options[0].selected = true;
  }
}
// -->
</script>
</head>
<body text=&quot;#000000&quot; bgcolor=&quot;#ffffff&quot;>
<form>
<select name=wl_cars>
<option value=&quot;-&quot;>-Cars-
<option value=ford>Ford
<option value=chevy>Chevy
</select> &nbsp;&nbsp;
<select name=wl_colors>
<option value=&quot;-&quot;>-Colors-
<option value=red>Red
<option value=blue>Blue
</select>
<br>
<input type=button name=wb_button value=&quot;check me&quot; onclick=&quot;doThis();&quot;>
<script language=javascript>
   document.forms[0].wl_cars.selectedIndex  = 1;
   alert(document.forms[0].wl_cars.selectedIndex);
</script>

<script language=javascript>
   alert(document.forms[0].wl_cars.selectedIndex);
</script>
</form>
</body>
</html>
Hope this helps,
Jessica
[ponytails2]
 
Yup. That's basically what I have for my code.

I tried your code in my version of netscape (6.2) and I got the same error.

Displayed 1 and then 0. I guess that means it's a netscape problem.

:)
 
thanks for your help. I really appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top