html - jquery for loop with given start and end -


i have 2 input boxes enter "from" , "to" values in each. reason works in range only, can't figure out why.

var = $('#from').val(); var = $('#to').val(); var total = ''; (i = from; <= to; i++) {      if (i == to)         total += i;      else         total += + ','; } console.log(total); 

so works when doing 1-10 i've tried 8-30 or 8-100 doesn't work...can't seem figure out why..

you have explicitly turn values (string) numbers first, otherwise you're stuck string comparison, i.e. '2' > '100'.

var = +$('#from').val(); var = +$('#to').val(); 

i'm using unary + operator that. use this:

var = parseint($('#from').val(), 10); var = parseint($('#to').val(), 10); 

refer this answer decide 1 better purposes. i'd go first one, short , sweet :)


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -