views:

139

answers:

4

HI, In javascript when value set to input hidden control,which event is occurPlz Help for me

A: 

I'm guessing that 'onchange' would fire.

graphicdivine
A: 

Yes this what you are looking for

<input type="hidden" name="hid" value="0" onchange="alert('Caught the hidden event');" />

Happy coding

Ravia
A: 

A value (aside from the initial value) can only be set on a hidden input by using scripting, and events do not generally fire in response to scripts.

It might trigger a Mutation event, but browser support for them is not all that widespread yet.

In general, if you want to do something when you script changes the value of a hidden input — make the script do the other thing at the same time.

David Dorward
A: 

Whenever you change the value of a hidden field using script, it wont fire any event. But you can manually trigger the event if you are using jQuery.

lets assume that you have the following hidden field

<input type="hidden" id="hid" value="0" onchange="alert('Caught the hidden event');" />

when you change teh value of the field using the following code it will not display the alert message.

$("#hid").val("2");

but you can trigger the change event using the following code

$("#hid").val("2").change();

the above code will display the alert message.

Elangovan