options.value not working in Firefox

Discussion in 'Javascript' started by grpramodkumar@gmail.com, May 7, 2007.

  1. Guest

    HI,


    function change(value,sub) {
    subcat = document.getElementById(sub);
    subcat.options.value = value;

    }


    <select id="aa">
    <option value="1">one</option>
    <option value="2">two</option>
    </select>

    <input type="button" value="Click" onclick="change(2,'aa');">


    I am trying to change the value of a select box dynamicaly on click ,
    the above code is working in IE , but not in firefox,

    Thanks,
     
    , May 7, 2007
    #1
    1. Advertising

  2. On May 7, 5:18 am, wrote:
    > HI,
    >
    > function change(value,sub) {
    > subcat = document.getElementById(sub);
    > subcat.options.value = value;
    >
    > }
    >
    > <select id="aa">
    > <option value="1">one</option>
    > <option value="2">two</option>
    > </select>
    >
    > <input type="button" value="Click" onclick="change(2,'aa');">
    >
    > I am trying to change the value of a select box dynamicaly on click ,
    > the above code is working in IE , but not in firefox,
    >


    subcat.value = value;
     
    scripts.contact, May 7, 2007
    #2
    1. Advertising

  3. ASM Guest

    a écrit :
    >
    > function change(value,sub) {
    > subcat = document.getElementById(sub);
    > subcat.options.value = value;
    > }
    >
    > <select id="aa">
    > <option value="1">one</option>
    > <option value="2">two</option>
    > </select>
    >
    > <input type="button" value="Click" onclick="change(2,'aa');">
    >
    >
    > I am trying to change the value of a select box dynamicaly on click ,
    > the above code is working in IE , but not in firefox,


    I do not understand the value of what you try to change
    nor what you give it as replacement ... ?

    If you want the drop down selector reflects the choice 2 :

    <button onclick="change(2, 'aa');">show item 2</button>


    function change(option, sub) {
    document.getElementById(sub).selectedIndex = --option;
    }


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
     
    ASM, May 7, 2007
    #3
  4. On May 7, 6:18 am, wrote:
    > HI,
    >
    > function change(value,sub) {
    > subcat = document.getElementById(sub);
    > subcat.options.value = value;
    >
    > }
    >
    > <select id="aa">
    > <option value="1">one</option>
    > <option value="2">two</option>
    > </select>
    >
    > <input type="button" value="Click" onclick="change(2,'aa');">
    >
    > I am trying to change the value of a select box dynamicaly on click ,
    > the above code is working in IE , but not in firefox,
    >
    > Thanks,


    I don't get it at all... You want ALL the options to have the same
    value as specified in the 1st parameter of the function??

    Then this workaround is 100% surely will work in both Firefox,
    Explorer and Konqueror ( I've tested it :) ).

    function change(value, sub)
    {
    var subCat = document.getElementById(sub);
    var childArray = subCat.childNodes;
    for(i = 0; i < childArray.length; i++)
    childArray.value = value;
    }

    Would you please be more specific about your requirement?
     
    Vicente Raúl Plata Fonseca [XnT], May 7, 2007
    #4
  5. Vicente Raúl Plata Fonseca [XnT] wrote:

    > function change(value, sub)
    > {
    > var subCat = document.getElementById(sub);
    > var childArray = subCat.childNodes;
    > for(i = 0; i < childArray.length; i++)
    > childArray.value = value;
    > }



    function change(value, sub)
    {
    var subCat = document.getElementById(sub);
    for(var i = 0; i < subCat.options.length; i++)
    subCat.options.value = value;
    }
     
    scripts.contact, May 7, 2007
    #5
  6. RobG Guest

    On May 7, 9:18 pm, wrote:
    > HI,
    >
    > function change(value,sub) {
    > subcat = document.getElementById(sub);


    There doesn't seem to be any reason for subcat to be global, so keep
    it local with var:

    var subcat = ...


    > subcat.options.value = value;


    subcat.options is an HTML Collection, it doesn't have a value property
    specified in the W3C specification. What happens when you set it is
    likely browser dependent - as you've discovered.


    > }
    > <select id="aa">
    > <option value="1">one</option>
    > <option value="2">two</option>
    > </select>
    > <input type="button" value="Click" onclick="change(2,'aa');">
    >
    > I am trying to change the value of a select box dynamicaly on click ,


    The value of a select *element* is based on the selected option. To
    change the selected option, change the select element's
    selectedIndex. The index is zero based, so to select the second
    option:

    subcat.selectedIndex = 1;

    <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-85676760>


    > the above code is working in IE , but not in firefox,


    It's always good to explain either what "working" or "not working" (or
    both) means.


    --
    Rob
     
    RobG, May 8, 2007
    #6
  7. scripts.contact wrote:
    > Vicente Raúl Plata Fonseca [XnT] wrote:
    >
    > > function change(value, sub)
    > > {
    > > var subCat = document.getElementById(sub);
    > > var childArray = subCat.childNodes;
    > > for(i = 0; i < childArray.length; i++)
    > > childArray.value = value;
    > > }

    >
    >
    > function change(value, sub)
    > {
    > var subCat = document.getElementById(sub);
    > for(var i = 0; i < subCat.options.length; i++)
    > subCat.options.value = value;
    > }

    Not W3C compliant. DOM objects otherwise are. That's why the script
    doesn't load in Firefox.
     
    Vicente Raúl Plata Fonseca [XnT], May 8, 2007
    #7
  8. ASM Guest

    Vicente Raúl Plata Fonseca [XnT] a écrit :
    > scripts.contact wrote:
    >> Vicente Raúl Plata Fonseca [XnT] wrote:
    >>
    >>> function change(value, sub)
    >>> {
    >>> var subCat = document.getElementById(sub);
    >>> var childArray = subCat.childNodes;
    >>> for(i = 0; i < childArray.length; i++)
    >>> childArray.value = value;
    >>> }

    >>
    >> function change(value, sub)
    >> {
    >> var subCat = document.getElementById(sub);
    >> for(var i = 0; i < subCat.options.length; i++)
    >> subCat.options.value = value;
    >> }

    > Not W3C compliant. DOM objects otherwise are. That's why the script
    > doesn't load in Firefox.
    >


    first time I hear that a not compliant W3C could break a JS ... !
    (both functions above work fine, and 2nd is better)

    What say you it is not W3C compliant ?

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
     
    ASM, May 8, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cliff  Martin
    Replies:
    1
    Views:
    3,084
    Larry Smith
    Jan 31, 2007
  2. jacksu
    Replies:
    0
    Views:
    537
    jacksu
    Oct 9, 2007
  3. Utkado
    Replies:
    2
    Views:
    2,232
  4. Bryan Richardson
    Replies:
    6
    Views:
    321
    Bryan Richardson
    Feb 25, 2008
  5. Sijo Kg
    Replies:
    1
    Views:
    110
    Justin Collins
    Jan 7, 2009
Loading...

Share This Page