performance - jQuery Multiple conditionals with isNumeric -


i'm trying figure out best practice couple of things.

  1. whether having if statements inside of if statements bad thing.
  2. 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -