By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

Trigger change event (urgent)

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Jul 23 '05 #2

P: n/a
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<c5*******************@news.demon.co.uk>...
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.