Click to See Complete Forum and Search --> : Accessing object: Netscape compatibility
Hi,
I have a weired kind of problem
The script that works in explorer, doesn't in netscape.
<select name=slot onChange=populateList(this)>
this doesn't work in netscape, inside populate when display the value, it says null.
I tried this
<select name=slot onChange=populateList(document.forms[0].slot)> bu giving full object access details.
populateList (slot) {
alert (slot.value)
}
This is select, so I don't know how can I get the VALUE of it.
In I.Explorer - slot.value gives me the value.
In Netscape - it returns null.
Please help
kari
Have you tried putting the event in quotes?
I always do:
onClick="populateList(this)"
You might also put in the semicolon afterwards, though thats rarely necessary, but it might help.
Yes I tried that as well.
Inside populateList(slot)
I even tried to access the object like this
alert(window.document.forms[0].slot.value)
It says null value, where as other elements like simple name/value pairs are accesible (<input type=hidden name=xx value=yy> can be accessed.
This is a drop down select.
olerag
08-06-2003, 03:32 PM
This should work in all browsers w/ JS enabled:
<html>
<head>
<script type="text/javascript">
function showSelected(listObj) {
for (var i=0;i<listObj.length;i++) {
if (listObj.options[i].selected) {
alert("Value: " + listObj.options[i].value);
break;
}
}
}
</script>
</head>
<body>
<center>
<b>Selection Test</b>
<p>
<form>
<select name=selectList1 size="5" onChange="showSelected(this)">
<option value="1">Item #1</option>
<option value="2">Item #2</option>
<option value="3">Item #3</option>
<option value="4">Item #4</option>
<option value="5">Item #5</option>
<option value="6">Item #6</option>
<option value="7">Item #7</option>
</select>
</form>
</center>
</body>
</html>
Use the selectedIndex property:
<script type="text/javascript">
function showSelected(obj) {
alert(obj.options[obj.selectedIndex].value);
}
</script>
</head>
<body>
<form>
<p><select name=selectList1 size="5" onChange="showSelected(this)">
<option value="1">Item #1</option>
<option value="2">Item #2</option>
<option value="3">Item #3</option>
<option value="4">Item #4</option>
<option value="5">Item #5</option>
<option value="6">Item #6</option>
<option value="7">Item #7</option>
</select></p>
</form>