javascript - jQuery check if any text input has value -


i want ask if there's better way in jquery select multiple text input check if of them has value. here's code:

if ($("#reference").val() != "" || $("#pin").val() != "" || $("#fname").val() != "" || $("#mname").val() != "" || $("#datepicker").val() != "") { /*logic goes here */ } 

you below:

if ($("#reference,#pin,#fname,#mname,#datepicker").filter(function() { return $(this).val(); }).length > 0) {   //.. } 

using common function following make reusable:

function hasvalue(elem) {     return $(elem).filter(function() { return $(this).val(); }).length > 0; } 

and call this:

hasvalue("#my-input-id"); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -