I want to do something with each hidden input value, so I coded the following javascript using jQuery.
$.each($("input[type='hidden']"), function (index, value) {
alert(value.val());
});
But I get he following execution error: value.val is not a function.
What am I doing wrong?
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.
The inputs can be filtered by specifying the :input selector in jQuery that selects every type of input on the element it is used. Next, we will use the each() method to iterate over the inputs to display the values or perform any operation as needed. Syntax: $('#id *').
The value of the hidden input is that it keeps the secret associated with the data and automatically includes it when the form is sent to the server. You need to use well-designed secrets to actually secure your website.
This would work:
$("input[type=hidden]").each(function() {
$(this).val() //do something with
});
The value in the iterating function is a Node, not a jQuery object.
You still need to go: $(value).val();
See the last example here: http://api.jquery.com/each/
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