onChange IE?

Discussion in 'Javascript' started by oscar.redondo@gmail.com, Oct 4, 2007.

  1. Guest

    Hi!

    I want to create a "select" by Javascript with this function:

    function cargaOpciones(iRow)
    {
    var i
    var sel = document.createElement('select');

    i=0
    sel.name='propRow' + iRow;
    sel.id='propRow' + iRow;
    sel.onChange="alert('Change');";

    while (i<document.forms[0].cboOpciones.options.length)
    {
    sel.options=new Option(i,i)

    i=i+1;
    }
    return sel
    }

    Unfortunatelly, the onChange event is never fired? Anyone can help me?

    Thanks in advance!
    , Oct 4, 2007
    #1
    1. Advertising

  2. RobG Guest

    On Oct 4, 4:06 pm, wrote:
    > Hi!
    >
    > I want to create a "select" by Javascript with this function:
    >
    > function cargaOpciones(iRow)
    > {
    > var i
    > var sel = document.createElement('select');
    >
    > i=0
    > sel.name='propRow' + iRow;
    > sel.id='propRow' + iRow;
    > sel.onChange="alert('Change');";


    Javascript is case sensitive, even if HTML isn't - so use onchange.
    And to satisfy a wider range of browsers, you need to assign a
    function object or reference to the onchange property:

    sel.onchange = function(){alert('Change');}


    though using onchange with a select element has usability issues.

    >
    > while (i<document.forms[0].cboOpciones.options.length)


    That would be more efficient as:

    var j = document.forms[0].cboOpciones.options.length;
    while (i<j)


    > {
    > sel.options=new Option(i,i)
    >
    > i=i+1;


    Why not:

    i++;



    --
    Rob
    RobG, Oct 4, 2007
    #2
    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. Zeebra3
    Replies:
    5
    Views:
    5,099
    pelegk1
    Jul 15, 2007
  2. Brendan Vogt

    POSTING A FORM USING onchange

    Brendan Vogt, Aug 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    470
    Leon Jollans
    Aug 28, 2003
  3. Kathy Burke
    Replies:
    1
    Views:
    1,117
    Severin
    Nov 10, 2003
  4. MDBloemker
    Replies:
    2
    Views:
    2,838
  5. =?Utf-8?B?TW9ua2V5Qm95?=
    Replies:
    2
    Views:
    434
    =?Utf-8?B?TW9ua2V5Qm95?=
    Jun 6, 2004
Loading...

Share This Page