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. Advertising

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

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

    Timo Nentwig, Feb 5, 2004, in forum: XML
    Replies:
    4
    Views:
    780
    Richard Tobin
    Feb 5, 2004
  2. palmiere
    Replies:
    1
    Views:
    471
    Erwin Moller
    Feb 9, 2004
  3. lawrence
    Replies:
    2
    Views:
    223
    lawrence
    Jun 2, 2004
  4. lawrence
    Replies:
    7
    Views:
    647
    lawrence
    Sep 29, 2004
  5. Rob
    Replies:
    4
    Views:
    295
Loading...

Share This Page