tags:

views:

58

answers:

3

I placed many textboxes on my page and all have the same class .myClass.

I want to check if all are filled out or not. How I can find out via jQuery?

+4  A: 
jensgram
please read question carefully i am worried about textbox not checkbox you understand ?
4thpage
@4thpage: You've written "check" so often that I've read "checkbox" myself, until I edited your question wording.
Tomalak
+2  A: 
if ($('input:text.myClass[value=""]').length > 0)
{
    // you have some text boxes which are empty
}
rahul
are it is suitable var q = $(".quan").each(function (index) { if ($(this).val() == "") { result == false; } });
4thpage
If you want to do something in the iteration then go for the `.each()` function.
rahul
The above code will filter the inputs of type text, class myclass and with empty values.
rahul
+1  A: 

Please see this, hope it helps. Also the code bellow will apply a $.trim() so that inputs filled with a space will validate as empty.

$("input.myClass").each(function(){
    if($.trim($(this).val()) == ""){
        // if you reach this then at least one textfield is not filled.
        // so this is where you decide what to do ( for example, assign FALSE to a 'all_textfileds_filled' variable )
    }
});

Cheers

whonoes
hi jensgram, I really meant 'filled' (as in http://www.thefreedictionary.com/filled) not 'field' as you corrected.
whonoes
@whonoes No, I just moved a misplaced parenthesis, cf. [revisions](http://stackoverflow.com/posts/3958806/revisions). You passed `$(this).val() == ""` to `$.trim()` :)
jensgram
@jensgram apologies, that was actually my mistake! thanks a lot for the correction
whonoes
@whonoes No problem.
jensgram
Thanks for the solutions, folks - worked as intended!
Dick Lampard