i just can't wrap my head around why to do it in JS. if you were to do it in JS, you would still need PHP to print all the JS logic to the screen, .. which is why i would ask why not just to PHP to HTML rather than PHP to JS to HTML.
Glad you found a solution for now though.
