Netscape 6 - adding an option to select 
Author Message
 Netscape 6 - adding an option to select

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?



Sat, 02 Aug 2003 18:17:34 GMT  
 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>&nbsp;&nbsp;
  <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?



Sat, 02 Aug 2003 19:45:36 GMT  
 Netscape 6 - adding an option to select

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)

Substituting...

   thing.appendChild(obj)

Works in both NN/Mozilla 5+ & IE 5+

As does thing.insertBefore() method.

- Peter



Sun, 03 Aug 2003 01:09:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. changing select options based on previously selected options

2. SELECT / Dynamic OPTIONS Netscape Sizing Issue

3. problem modifying select options under Netscape

4. add option to select list

5. Adding options to a select element

6. add new option item to the select from another frame

7. Add Option string to select control?

8. Prob when adding new OPTION to SELECT

9. Dynamically adding OPTION to SELECT

10. Prob when adding new OPTION to SELECT

11. Add option method to form.select object

12. how to add OPTION element in SELECT at runtime using Client side vbscripting

 

 
Powered by phpBB® Forum Software