developer747
developer747

Reputation: 15928

Find rows in a table where hidden field has value

I have a table where every row has a hidden control as shown below

<input name="ID" id="ID" type="hidden"/>

But some of them have values and others don't. How do I filter out the rows that have no value

I know it would be something like

$('#myTable tr').filter(... ???

What I am trying to do is, get the rows where the hidden control has a value, then fetch certain controls and their values from those rows and post them using jquery ajax.

Upvotes: 3

Views: 4295

Answers (4)

Jo&#227;o Silva
Jo&#227;o Silva

Reputation: 91299

Use the following:

$('#myTable tr').filter(function () {
  return $(this).find('input[type="hidden"][value!=""]').length;
});

DEMO.

Upvotes: 3

user463231
user463231

Reputation:

Building off of João's answer, to get the row you just need to take his second option and traverse up to the parent.

$('#myTable tr input[type="hidden"][value!=""]').parent();

That is assuming the hidden input is a direct descendent of the <tr>. Otherwise you may want to use the jQuery parents() function like so:

$('#myTable tr input[type="hidden"][value!=""]').parents('tr');

Upvotes: 2

Dariush Jafari
Dariush Jafari

Reputation: 5443

the selector 'input[value]' selects all inputs having a value attribute.

$("#myTable input[value], #myTable input[value!='']").doSomthing(...);

Upvotes: 1

bytecode77
bytecode77

Reputation: 14830

Add a class to it:

<input name="ID" id="ID" type="hidden" class="someclass" />

$('#myTable tr .someclass').doSomething(...)

Upvotes: 1

Related Questions