---------------------
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
---------------------
wow, it worked..
after posting i realised the Cap-Letter 'V' => value.. neways my last
question.. how do i deal with this????
anOption.selected = true;
thnx a lot!!!
Martin Honnen wrote:
mi******@gmail.com wrote:
Hi wats wrng with this code??? it works fine on IE6 but not on FireFox
1.5???
var anOption = document.createElement("OPTION");
document.getElementById("category").options.add(an Option);
The W3C DOM Level 2 HTML defines an add method for the select element object
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980>
but not for the options collection. However using that method is
difficult as IE implements the method with the same name with different
parameters.
If you simply want to add an option then using the DOM Level 0
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerText = "NewElement";
Firefox does not support the innerText property at all. For option
element objects you can set
anOption.text
anOption.Value = "99";
JavaScript is case sensitive, the property is named value and not Value.
--
Martin Honnen
http://JavaScript.FAQTs.com/