Ah, I think I see the mistake. In the JavaScript code, where you declared the arrays, you need to add id = [], because otherwise JavaScript doens't understand what "id[p]" is. Also, instead of using p = p+1, just type p++.I recommend re-writing the code, because it's generally not a good idea to have the PHP and HTML mixed up. In other words, try to keep them separate, and instead have funtions to echo the JavaScript.