Here is my little debugging alert. Almost threw my monitor out of the window. Look only on the highlighted code. On what conditions on earth could this alert be triggered like that? - http://i.stack.imgur.com/nrf1x.png
Here is full fiddle, but I don't think it's important: http://jsfiddle.net/Timson/QqVrF/8/
if (currLoad > maxload){
alert("I am dumbass, I think that "+currLoad+' is more than '+maxload);
}
Is it possible that the variables are both strings? In a javascript console:
6 > 1000
false
"6" > "1000"
true
try :
if (parseInt(currLoad) > parseInt(maxload)){
alert("I am dumbass, I think that "+currLoad+' is more than '+maxload);
}
As the earlier answer said you're probably comparing strings..
You get these values from form inputs so they are strings. Comparing strings is different than numbers so "6" > "1000"
is true while 6 > 1000
is false.
Each number you obtain from form inputs should be parsed to number if it's supposed to be a number. Use for example parseInt
or Number
function. For instance: parseInt(currLoad, 10)
etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.