
Netscape 6 - adding an option to select
Dave,
The example given in the Netscape JavaScript documentation is as follows:
jeans = new Option("Blue Jeans", "jeans", false, false);
myList.options[myList.length] = jeans;
I've tested the following in IE 5.5 and it's worked in that, and as the
method comes from Netscape themselves, I'm going to have to assume it works
in their browsers... ;-)
<html>
<head>
<title>Option Test</title>
</head>
<script>
var myLine = 1;
function addOption(objSelect) {
myLine++;
objNewOpt = new Option("..." + myLine, "Line " + myLine, false, false);
objSelect.options[objSelect.length] = objNewOpt;
Quote:
}
</script>
<body>
This is a test...
<form name="frmTest">
<select name="dlbTest">
<option selected value="Line 1">...1</option>
</select>
<input type="button" name="btnTest" value="Add..."
onclick="addOption(dlbTest)">
</form>
</body>
</html>
HTH,
Tony.
Quote:
> Got some code that works in IE but not in Netscape. Trying to use the ADD
> method in DHTML to add an option element. I create the element first
using
> createElement then add it
> var thing = document.getElementById(idreference)
> var obj = document.createElement("OPTION")
> obj.value=XXX
> obj.text=XXX
> thing.add(obj)
> Netscape reports
> "Parameter is not an object" code : "1003" nsresult "0x805303eb
> (NS_ERROR_DOM_NOT_OBJECT_ERR)
> typeof(obj) returns the value "object" as you would expect.
> Anyone got any ideas?