performance - jQuery Multiple conditionals with isNumeric -
i'm trying figure out best practice couple of things.
- whether having
if
statements inside ofif
statements bad thing. - if there better way condense code i'm not chaining bunch of logical operators chained together.
also can't figure out why isnumeric
not working, i've got simple form couple of input boxes , i'm looping around them in jquery. happens can input string of letters > 5 , won't hit isnumeric
conditional. ideally user has enter numbers this. ideas?
$("form :input").each(function(){ if(this.id = "zipcode" && $(this).val().length < 5 && $(this).is(":visible")){ if($.isnumeric($(this).val())){ //do } } });
you're passing wrong parameter isnumeric
function. line
if($.isnumeric($(this.val())){
should be
if($.isnumeric($(this).val())){
as long list of conditionals, can refactor them separate function name reflects purpose. in case example, create function this:
function isvalidzipcode(field) { return field.id = "zipcode" && $(field).val().length < 5 && $(field).is(":visible"); }
then looks cleaner this:
if(isvalidzipcode(this)){ if($.isnumeric($(this).val())){ //do } }
Comments
Post a Comment