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

3

17

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

Vimineous answered 8/1, 2010 at 9:51 Comment(1)
Please clarify your question. It's unreadable, and unclear at the moment. Click on Edit and remake it.Hooked
I
22

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.

Islam answered 25/5, 2010 at 17:18 Comment(0)
H
2

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.

Hibernia answered 8/1, 2010 at 11:44 Comment(0)
G
-6

I'm guessing that 'onchange' would fire.

Gesticulation answered 8/1, 2010 at 10:1 Comment(1)
Nope, onchange doesn't fire when changing the value from JS.Burnard

© 2022 - 2024 — McMap. All rights reserved.