>      $('input:text.required').each(function() {
>           var val = (this.value.length);
>                if (val == 0)
>                     { $('#submit').attr('disabled', 'disabled'); }
>      });

I think this is equivalent to:

if ( $(':text.required[value=""]').length )
   $('#submit').attr('disabled', 'disabled');

That does allow a field with just spaces to qualify, but on my forms I
typically make this check on a submit handler and have already trimmed
spaces off all text fields at the top of that handler to simplify the
later logic:

$(":text").each(function(){
   this.value = this.value.replace(/^\s+|\s+$/g,""));
});

The other way to find fields that are just blanks would be to create a
custom selector:

jQuery.extend(jQuery.expr[':'], {
    blank: function(a) {
       return !a.value || !/^\s+$/.test(a.value);
    }
})

and use it this way:

if ( $(':text.required:blank').length )
   $('#submit').attr('disabled', 'disabled');

> - How do I modify ('input:text.required') to accommodate other types of 
> required inputs?
> - I tried ('input:text.required, input:select.required') and
>           ('input:text.required', 'input:select.required') but that didn't 
> work
>

Since the select is its own element, you'd use something like

$(':text.required, select.required')
  or
$(':text, select').filter('.required')

If you're doing a lot of forms on a regular basis, you might also want
to check out the validate plugin:

http://jquery.bassistance.de/validate/demo/

No matter what, good form validation is a pain. At this point I'm sure
you agree... :-)

Reply via email to