...

View Full Version : variable valuation in the for statement



NorbNYC
11-11-2012, 01:29 AM
Hi folks.

I know numbertohide = 2.

How come

for (var h=numbertohide;h<6;h++)
{

inputselectionelementid = '#inputselection' + h;
$(inputselectionelementid).hide();
console.log('hide ' + inputselectionelementid);
}
does not work? Only var h=2 directly properly executes the loop.

Thanks

DanInMa
11-11-2012, 02:46 AM
not sure why, bt they way you've formed your code, I can tell you theres probably an easier way to do what you are doing, since you are apparently using jQuery.

Would you mind showing some more, maybe we can help you reach your overall goal a little better?


- loop looks fine to me, most likely answer is that numbertohide isnt coming to 2, like you think it is

NorbNYC
11-11-2012, 01:35 PM
Yup it was my mistake, numbertohide wasn't actually coming out to 2.

Thanks Dan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum