geoff swartz
geoff swartz

Reputation: 1

jquery syntax to look for a hidden field in a form

I have a form with a table in it. In each row is a table cell with a hidden input item with the name of it starting with "hf_id_" followed by a number so that row 1's field has a name of "hf_id_1", row 2 is "hf_id_2" and so on. I need to search all of these fields for a particular value but I'm not quite sure how to get to the hidden fields. I know how to get to them when the full name is known but in this case I'm not sure if there's a way to get an array of these where name starts with "hf_id_". Thanks.

Upvotes: 0

Views: 179

Answers (2)

mmhan
mmhan

Reputation: 731

Or you could simply use

  $('input[type="hidden"]');

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382716

You can search elements with ^ (starting with) and $ (ending with), example:

$('input[name^="hf_id_"]');

So you can get all those elements like:

var elements = $('input[name^="hf_id_"]');

And you can iterate over them to search for a particular value like:

$('input[name^="hf_id_"]').each(function(){
  if ($(this).val() === 'search value here')
  {
     // found..........
  }
}); 

Upvotes: 1

Related Questions