tags:

views:

229

answers:

1

Hello

i have a form, how to check if all the elements inside a form "textbox, checkbox, textarea, select, file" are not empty ??

THanks

+4  A: 

You can see if any are empty like this:

$(":input").each(function() {
   if($(this).val() === "")
    alert("Empty Fields!!");
});

You can read on the :input selector here

for a more specific answer, if you only want those types, change the selector like this:

$(":text, :file, :checkbox, select, textarea").each(function() {
   if($(this).val() === "")
    alert("Empty Fields!!");
});
Nick Craver
+1 for `$(":text, :file, :checkbox, select, textarea")` each part..
c0mrade
.val() doesn't work with :checkbox
From.ME.to.YOU
Nick Craver