Petty_Crim Posted January 11, 2008 Share Posted January 11, 2008 I've got this loop which seems to behaving badly for some reason rather then going +1 it instantly jams the figure 10 into my function parameter. I've placed a # in front of the the parameter: (position_count==9) for (i=1; i<=position_count; i++) { text_button="position_button"+i; if (i==position_num) { document.getElementById("status"+position_num).innerHTML="<font color='red'><i><center>FREE</center></i></font>"; document.getElementById(text_button).value='Apply'; document.getElementById(text_button).onclick= function () {ajaxFunction(#i, 0, position_count)}; } else { document.getElementById("i"+i).innerHTML=i; document.getElementById(text_button).value=i; document.getElementById(text_button).style.visibility='visible'; document.getElementById(text_button).onclick= function () {ajaxFunction(#i, 0, position_count)}; } } It should output 1-9 in that parameter but it goes straight to 10. Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted January 11, 2008 Author Share Posted January 11, 2008 Anyone know? My loop is outputting 1-9 for the button names, but for some reason when it comes to the function it just slams in a big 10. Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted January 11, 2008 Author Share Posted January 11, 2008 Okay I solved it using this: (function(i) { var u = i; document.getElementById(text_button).onclick= function() { ajaxFunction(u, 0, position_count)}; })(i); It seems when you place a function in a loop using the value thats getting incremented it waits and then inputs the last value of the number being incremented in this case 10. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.