Forum Moderators: open

Message Too Old, No Replies

javascript: IE7 won't divide properly? 100/6

         

carsten888

9:34 am on Sep 29, 2009 (gmt 0)

10+ Year Member



I am trying to make a percentage by deviding a 100 through a value. Works fine in FF but IE7 choocks on it, throwing an error.

this works:
part = 100/6;
alert(part);

this does not: (in IE7)
temp = 6;
percent = 100/temp;
alert(percent);

What blatently silly thing am I overlooking here?

carsten888

11:28 am on Sep 29, 2009 (gmt 0)

10+ Year Member



I had this code in a function and it turns out IE7 needs the var 'percent' to be declared outside the function for this to work :-0#

whoisgregg

2:38 am on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You ran into a variable scope issue. :) Instead of letting the variable have local scope inside the function, IE7 required it to have global scope outside the function.

carsten888

6:09 am on Sep 30, 2009 (gmt 0)

10+ Year Member



I see. thanks.