finding all empty text fields with jQuery

Needed to do a basic validation check for a client which simply told the user that not all the fields have been completed are they sure they want to continue. Turns out jQuery made this simples with the command $(":text[value=]") which returns all the objects. In the end my (cut down) function that I used on submit of the form was:

view plain print about
1function emptyFieldCount(){
2    var fieldCnt = $(":text[value=]");
3    var isOk = true;
4    if(fieldCnt.length >
10){
5        isOk = confirm('Are you sure you want to continue, not all fields have been filled out');
6    }
7    return isOk;
8}

Posted: 04-Dec-2010

View: 2891

Permalink: here

Comments

function emptyFieldCount(){
return $(":text[value=]").length < 11 || confirm('Are you sure you want to continue, not all fields have been filled out');
}

#1 johans
04/Dec/10 8:22 PM