Trigger change event (urgent)

  • Thread starter R. Rajesh Jeba Anbiah
  • Start date
R

R. Rajesh Jeba Anbiah

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

Richard Cornford

R. Rajesh Jeba Anbiah wrote:
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.
 
R

R. Rajesh Jeba Anbiah

Richard Cornford said:
R. Rajesh Jeba Anbiah wrote:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top