document.createElement("OPTION") + FireFox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • millw0rm@gmail.com

    #1

    document.createElement("OPTION") + FireFox

    Hi wats wrng with this code??? it works fine on IE6 but not on FireFox
    1.5???

    var anOption = document.create Element("OPTION ");
    document.getEle mentById("categ ory").options.a dd(anOption);
    anOption.innerT ext = "NewElement ";
    anOption.Value = "99";

  • Martin Honnen

    #2
    Re: document.create Element("O PTION") + 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.create Element("OPTION ");
    > document.getEle mentById("categ ory").options.a dd(anOption);[/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.elemen ts.selectName;
    select.options[select.options. length] = new Option('text', 'value');
    is much better in terms of browser compatibility.
    [color=blue]
    > anOption.innerT ext = "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/

    Comment

    • millw0rm@gmail.com

      #3
      Re: document.create Element(&quot;O PTION&quot;) + FireFox

      ---------------------
      var select = document.forms. formName.elemen ts.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.select ed = 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.create Element("OPTION ");
      > > document.getEle mentById("categ ory").options.a dd(anOption);[/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.elemen ts.selectName;
      > select.options[select.options. length] = new Option('text', 'value');
      > is much better in terms of browser compatibility.
      >[color=green]
      > > anOption.innerT ext = "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]

      Comment

      • millw0rm@gmail.com

        #4
        Re: document.create Element(&quot;O PTION&quot;) + FireFox

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


        solved it!!!!!

        thnx


        millw0rm@gmail. com wrote:[color=blue]
        > ---------------------
        > var select = document.forms. formName.elemen ts.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.select ed = 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.create Element("OPTION ");
        > > > document.getEle mentById("categ ory").options.a dd(anOption);[/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.elemen ts.selectName;
        > > select.options[select.options. length] = new Option('text', 'value');
        > > is much better in terms of browser compatibility.
        > >[color=darkred]
        > > > anOption.innerT ext = "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]

        Comment

        • Martin Honnen

          #5
          Re: document.create Element(&quot;O PTION&quot;) + 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/

          Comment

          Working...