great file sharing site
Wednesday, October 27, 2010
Dynamically create drop down list for maximum compatibility
The W3C DOM Level 2 HTML defines an add method for the select element object
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.
[color=blue]
> anOption.innerText = "NewElement";[/color]
Firefox does not support the innerText property at all. For option
element objects you can set
anOption.text
[color=blue]
> anOption.Value = "99";[/color]
JavaScript is case sensitive, the property is named value and not Value.
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.
[color=blue]
> anOption.innerText = "NewElement";[/color]
Firefox does not support the innerText property at all. For option
element objects you can set
anOption.text
[color=blue]
> anOption.Value = "99";[/color]
JavaScript is case sensitive, the property is named value and not Value.
Tuesday, October 26, 2010
Mozilla id attr issue
Mozilla seems to have problem when mixing small cap n big caps letter in the id attr, example <div id="txtVAns">, better use all small caps next time
Subscribe to:
Posts (Atom)