Adding onChange to Select box value doesn't do anything

Discussion in 'Javascript' started by javelin, Apr 17, 2008.

  1. javelin

    javelin Guest

    I have this code to add an onChange event to a select control:

    catid.attributes['onChange'].value= "FilterByCatID();";
    alert(catid.attributes['onChange'].value);

    The alert box confirms that the event has been set, but on change of
    the selectbox, nothing happens. Any ideas what I'm missing?

    Thx.

    Jav
     
    javelin, Apr 17, 2008
    #1
    1. Advertisements

  2. javelin

    RobG Guest

    On Apr 17, 10:59 am, javelin <> wrote:
    > I have this code to add an onChange event to a select control:
    >
    > catid.attributes['onChange'].value= "FilterByCatID();";
    > alert(catid.attributes['onChange'].value);
    >
    > The alert box confirms that the event has been set, but on change of
    > the selectbox, nothing happens. Any ideas what I'm missing?


    You've created an "onChange" attribute with a string value, what you
    want to do is assign a function to the onchange handler. The most
    reliable way is to set it directly:

    catid.onchange = FilterByCatID;


    Also, it is a convention in javascript that function names starting
    with a captial letter are reserved for constructors.


    --
    Rob
     
    RobG, Apr 17, 2008
    #2
    1. Advertisements

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. Timo Nentwig

    XPath: //B[2] doesn't select anything

    Timo Nentwig, Feb 5, 2004, in forum: XML
    Replies:
    4
    Views:
    912
    Richard Tobin
    Feb 5, 2004
  2. Vasu
    Replies:
    2
    Views:
    763
    Knute Johnson
    Oct 18, 2008
  3. palmiere
    Replies:
    1
    Views:
    674
    Erwin Moller
    Feb 9, 2004
  4. lawrence
    Replies:
    2
    Views:
    291
    lawrence
    Jun 2, 2004
  5. Robert Carlson
    Replies:
    2
    Views:
    227
    Richard Cornford
    Sep 14, 2004
  6. lawrence
    Replies:
    7
    Views:
    777
    lawrence
    Sep 29, 2004
  7. Replies:
    6
    Views:
    383
  8. Rob
    Replies:
    4
    Views:
    363
Loading...