HI, In JavaScript when value is set to a hidden input control, which event is fired?
Definition and Usage The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.
Whenever the value of a form field changes, it fires a "change" event.
The oninput event occurs when an element gets user input. This event occurs when the value of an <input> or <textarea> element is changed.
The input event fires when the value of an <input> , <select> , or <textarea> element has been changed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With