Trigger change event (urgent)

Discussion in 'Javascript' started by R. Rajesh Jeba Anbiah, Apr 15, 2004.

  1. I have Googled a lot, but couldn't still find the answer...

    I could see, I can trigger the "click" event like:
    button_object.Click()

    But, I need to trigger the onChange() of select options. I couldn't
    find anything like:
    select_object.Change()

    More specifically, I have something like:
    <select name="sel" onChange="alert(this.selectedIndex)">
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>

    and I have something in JS like:
    form1.sel.selectedIndex = 2; //changing
    If I change the index, it doesn't trigger the onChange event. I
    wish to trigger the change event. Is there anyway to go with
    JavaScript or JScript? TIA.

    --
    http://www.sendmetoindia.com - Send Me to India!
    Email: rrjanbiah-at-Y!com
     
    R. Rajesh Jeba Anbiah, Apr 15, 2004
    #1
    1. Advertising

  2. R. Rajesh Jeba Anbiah wrote:
    <snip>
    > and I have something in JS like:
    > form1.sel.selectedIndex = 2; //changing

    <snip>

    Assuming - form1 - is a local variable holding a reference to the form
    element (rather than a browsers specific shortcut reference, with the
    consequent removal of any hope of cross browser support for a task that
    every javascript enabled browser is capable of), then you can just call
    the - onchnge - handler function yourself as:-

    form1.sel.onchange();

    Richard.
     
    Richard Cornford, Apr 15, 2004
    #2
    1. Advertising

  3. "Richard Cornford" <> wrote in message news:<c5l77h$ev4$1$>...
    > R. Rajesh Jeba Anbiah wrote:
    > <snip>
    > > and I have something in JS like:
    > > form1.sel.selectedIndex = 2; //changing


    <snip>
    > then you can just call
    > the - onchnge - handler function yourself as:-
    >
    > form1.sel.onchange();


    Oh cool! Thanks a lot. Never thought that it will be this much
    easier:) Thanks again.

    --
    http://www.sendmetoindia.com - Send Me to India!
    Email: rrjanbiah-at-Y!com
     
    R. Rajesh Jeba Anbiah, Apr 15, 2004
    #3
    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. David
    Replies:
    3
    Views:
    2,686
    news.microsoft.com
    Dec 2, 2004
  2. hiwa
    Replies:
    1
    Views:
    451
    Jon A. Cruz
    Feb 23, 2004
  3. =?Utf-8?B?TWFlIExpbQ==?=

    Urgent: Trigger javascript function after bind control

    =?Utf-8?B?TWFlIExpbQ==?=, Jun 7, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    532
    Bill Gregg
    Jun 7, 2006
  4. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    1,698
    rantingrick
    Jun 23, 2010
  5. xhe
    Replies:
    1
    Views:
    129
    Randy Webb
    Feb 9, 2007
Loading...

Share This Page