Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate over all input hidden values using $.each

Tags:

jquery

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?

like image 777
mmutilva Avatar asked Mar 12 '11 18:03

mmutilva


People also ask

How do you get hidden inputs?

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.

How to get input value in jQuery each function?

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 *').

Why input type hidden is used?

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.


2 Answers

This would work:

$("input[type=hidden]").each(function() {
     $(this).val() //do something with
});
like image 51
C. E. Avatar answered Oct 19 '22 18:10

C. E.


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/

like image 23
Dimitry Avatar answered Oct 19 '22 19:10

Dimitry