7

How do you calculate the number of input boxes with no value in a table row using jquery?

example:

<table id="table1">
<tr class="data" id="row5">
<td><input type="text" value="20%" /></td>
<td><input type="text" value="10%" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" /></td>
</tr>
<table>

I'm looking for answer = 2

3
  • i looking for something like $('#row5 > td input[type=text][value=]').length, but obviously my jquery is wrong Commented May 31, 2010 at 8:20
  • ok, sorry guys, looks like i got it wrong again :empty didn't work, but its looks like .find('input:text[value=""]') does, will do some more testing and then reselect the correct answer Commented May 31, 2010 at 8:43
  • please look at my demo in my answer... Commented May 31, 2010 at 8:54

2 Answers 2

6

Even that the OP claimed the answer as correct and working, this comes from the api doc:

Some other elements, on the other hand, are empty (i.e. have no children) by definition: input, img, br, and hr, for example.

So actually, it should be impossible to do it with the :empty selector.

$('input:empty').length

or to be more specific:

$('#table1').find('input:empty').length

even more specific:

$('#table1').find('input[type=text]:empty').length
Sign up to request clarification or add additional context in comments.

8 Comments

i think it's clear that with no value in a table row above... 'row' :)
are you sure about that? :p I guess I have to correct my answer, it seems like the :empty returns 'empty' by definition for input elements
ahh yes.. I have no doubt with the :empty at all... it's just that the question title says in a table row... not in a table.... ahh never mind.. :)
Am I out of line here? :empty really does work for empty values in input boxes?
title : Count number of empty input boxes in table row. In A Table Row... that is just my point... the OP's example is just 1 row... but I see it has an id of row5.. by that I can say there are lot's of row (tr)... and the OP wanted it by row... as in the title of the question above... not in a table... maybe like $('#table1 tr').each(function() { $(this).find('input:empty').length });
|
2

You can do like:

alert($('#table1 input:text[value == ""]').length);

5 Comments

i think it's clear that with no value in a table row above... 'row' :)
@Reigel: Ultimately input will go inside the table>tr>td.
@Reigel: Nope, it counts empty text boxes in the table.
ahhh yeah... It's just I think he wanted it by rows... ..table row.. from above...
Getting Syntax error, unrecognized expression: #table1 input:text[value == ""]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.