Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery check form to see if any inputs has value

Tags:

jquery

if ($('#requestForm').val == "") {
alert('Please select at least one filter');
    //return false;
}
else { 
    ///Run my code
}

I have a form, no inputs are required, but if no inputs are selected I want an alert to tell them to select at least one option.

like image 554
user1253239 Avatar asked May 02 '12 12:05

user1253239


1 Answers

var validate= false;
$('#requestForm input').each(function(){
    if($(this).val() != '' || $(this).attr('checked'))
        validate = true;
});
if(!validate){
    alert('Please select at least one filter');
    return false;
}
else { 
    Run my code
}
like image 75
Dattatray Walunj Avatar answered Oct 01 '22 03:10

Dattatray Walunj