Connecting Tech Pros Worldwide Help | Site Map

document.createElement("OPTION") + FireFox

millw0rm@gmail.com
Guest
 
Posts: n/a
#1: March 23rd, 2006, 11:40 AM
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);
anOption.innerText = "NewElement";
anOption.Value = "99";

Martin Honnen
Guest
 
Posts: n/a
#2: March 23rd, 2006, 12:15 PM

re: document.createElement("OPTION") + FireFox




millw0rm@gmail.com wrote:
[color=blue]
> 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);[/color]

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.
[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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
millw0rm@gmail.com
Guest
 
Posts: n/a
#3: March 23rd, 2006, 01:15 PM

re: document.createElement("OPTION") + FireFox


---------------------
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:[color=blue]
> millw0rm@gmail.com wrote:
>[color=green]
> > 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);[/color]
>
> 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.
>[color=green]
> > anOption.innerText = "NewElement";[/color]
>
> Firefox does not support the innerText property at all. For option
> element objects you can set
> anOption.text
>[color=green]
> > anOption.Value = "99";[/color]
>
> JavaScript is case sensitive, the property is named value and not Value.
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/[/color]

millw0rm@gmail.com
Guest
 
Posts: n/a
#4: March 23rd, 2006, 01:45 PM

re: document.createElement("OPTION") + FireFox


new Option('text', 'value', 'TRUE');


solved it!!!!!

thnx


millw0rm@gmail.com wrote:[color=blue]
> ---------------------
> 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:[color=green]
> > millw0rm@gmail.com wrote:
> >[color=darkred]
> > > 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);[/color]
> >
> > 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.
> >[color=darkred]
> > > anOption.innerText = "NewElement";[/color]
> >
> > Firefox does not support the innerText property at all. For option
> > element objects you can set
> > anOption.text
> >[color=darkred]
> > > anOption.Value = "99";[/color]
> >
> > JavaScript is case sensitive, the property is named value and not Value.
> >
> >
> > --
> >
> > Martin Honnen
> > http://JavaScript.FAQTs.com/[/color][/color]

Martin Honnen
Guest
 
Posts: n/a
#5: March 23rd, 2006, 01:55 PM

re: document.createElement("OPTION") + FireFox




millw0rm@gmail.com wrote:
[color=blue]
> new Option('text', 'value', 'TRUE');
>
>
> solved it!!!!![/color]

Pass in a boolean there e.g.
new Option('text', 'value', true, true)
where the third argument is for the default selected and the fourth for
the selected value (both which are boolean values).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in line: var theRow = table.createElement("tr") r_ahimsa_m@poczta.onet.pl answers 7 July 4th, 2008 08:15 AM
Setting "text" value to "option" element in IE gabon answers 2 November 23rd, 2005 03:33 AM