Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old March 23rd, 2006, 11:40 AM
millw0rm@gmail.com
Guest
 
Posts: n/a
Default document.createElement("OPTION") + FireFox

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";

  #2  
Old March 23rd, 2006, 12:15 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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/
  #3  
Old March 23rd, 2006, 01:15 PM
millw0rm@gmail.com
Guest
 
Posts: n/a
Default 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]

  #4  
Old March 23rd, 2006, 01:45 PM
millw0rm@gmail.com
Guest
 
Posts: n/a
Default 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]

  #5  
Old March 23rd, 2006, 01:55 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.