What event can be captured when an HTML hidden input value is set / changed

user239635 picture user239635 · Jan 8, 2010 · Viewed 12.4k times · Source

HI, In JavaScript when value is set to a hidden input control, which event is fired?

Answer

Elangovan picture Elangovan · May 25, 2010

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 the value of the field using 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();

Above code will display the alert message.