Reputation: 13
I'm after a little help with a complicated (for me!) jquery statement...
Basically I have a questionnaire, with 30 questions. Each question (in a table row) is made up of a group of 5 radio buttons. However, for some questions, as well as the radio group, there is also a select box - for this question to be 'complete' the select box needs to have a value selected (the first option having an empty value) as well as a radio selected.
OK - so I want to show how many questions have been completed - or how many are left to do...
So I need to count up each row considered 'complete' - in pseudo, something like
count the number of rows with
radio buttons and one of those radios selected
but remove any row which also has a select box, if that select box hasnt had an option chosen
Hope that makes sense...
I can get all the questions where there are unselected radios -
var unanswered = $('#myTable tr:has(:radio):not(:has(:radio:checked))').length;
or kill the not to count those rows with selected radios, but the select boxes are killing me. Just can't seem to grab hold of those rows with an unselected select box, not to mention combining it with the radio part!
Any help very very appreciated!
Thanks, Calvin
Upvotes: 1
Views: 224
Reputation: 2165
var unanswered2 = $('#myTable tr:has(option):not(:has(option[value!=""]:selected))').length;
^Get all tr
with option
's but not those which have empty value
and are selected. (Not tested on animals).
edit: I have add !
.
Upvotes: 1