Connecting Tech Pros Worldwide Forums | Help | Site Map

Trigger change event (urgent)

R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#1: Jul 23 '05
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

Richard Cornford
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Trigger change event (urgent)


R. Rajesh Jeba Anbiah wrote:
<snip>[color=blue]
> and I have something in JS like:
> form1.sel.selectedIndex = 2; //changing[/color]
<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. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Trigger change event (urgent)


"Richard Cornford" <Richard@litotes.demon.co.uk> wrote in message news:<c5l77h$ev4$1$8302bc10@news.demon.co.uk>...[color=blue]
> R. Rajesh Jeba Anbiah wrote:
> <snip>[color=green]
> > and I have something in JS like:
> > form1.sel.selectedIndex = 2; //changing[/color][/color]

<snip>[color=blue]
> then you can just call
> the - onchnge - handler function yourself as:-
>
> form1.sel.onchange();[/color]

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
Closed Thread