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
Post a Comment