ShaunP1989 Posted March 13, 2007 Share Posted March 13, 2007 Hi there I am kind of new to javascript programming and Im having an error with some code. Firstly I output checkboxes, using php, checkboxes are outputed according to what data is in the database. Each checkbox is given a unique name, chkP[count], where count is a numerical value depending on how many checkboxes have been outputed, the first one therefore being called chkP0, followed by chkP1 etc. I then store the total value of count in a hidden field. In my testing it is 7. The problem comes when I try to recover this value in javascript. The html code for the hidden field is: <input type="hidden" name="hidpcount" id="pcount" value="7"> I then get the value into javascript using the following javascript code: element = document.getElementById('pcount'); pcount = element.value; pcount--; Once this code has been executed the variable pcount holds 6. The problem I get is when i try to use this variable in a for loop: for (i = 0; i <= pcount; i++) { checkbox = "chkP" + i; element = document.getElementById(checkbox); if (element.checked) { donecol = true; } } The code will reach the start of the for loop, and then instead of running the code in the for loop it will go to the code after the for loop. The code will run if I replace the varibale pcount with the value 6 in the for loop statement. So I am looking with the problem somewhere withing the pcount variable. I hope someone can point me in the right direction as to where the error may lie. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 14, 2007 Share Posted March 14, 2007 Well, alert pcount after the assignment... 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.