ninedoors Posted October 2, 2008 Share Posted October 2, 2008 Right now I have a function that works with a static array that is defined inside the function: function put_picker(){ var vals = [1,2,3,4,5,6,7,8, 9,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24, 25,26,27,28,29,30,33,40,41, 44,46,51,54,55,66,68,69, 73,77,83,87,88,91,93,97,]; document.write('<div id="container" class="picker_container" style="width:239px">'); for (ev in vals){ document.write('<div class=box onclick="s(this)">'+vals[ev]+'</div>\r\n '); } document.write('</div>'); } All this does is use css to make a table of numbers that are clickable (basically a number pad). I would like to be able to make it so the array is created in my php function and then passed to the javascript function for output. Here is what I have tried so far with no luck. function put_picker(vals){ document.write('<div id="container" class="picker_container" style="width:239px">'); for (ev in vals){ document.write('<div class=box onclick="s(this)">'+vals[ev]+'</div>\r\n '); } document.write('</div>'); } <?php echo "<script type=\"text/javascript\"> var vals = new array(".join(',' , $vals)."); put_picker(vals); </script> And then I tried put the JS right in the code but still no luck: <?php echo "<script type=\"text/javascript\"> var vals = new array(".join(',' , $vals)."); document.write('<div id=\"container\" class=\"picker_container\" style=\"width:239px\">'); for (ev in vals){ document.write('<div class=box onclick=\"s(this)\">'+vals[ev]+'</div>\r\n '); } document.write('</div>'); </script>"; ?> I have looked at the source html that is created from the above code and the array seems to be created fine, it's just not passing it properly to the javascript. Any help would be great. Thanks Nick Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted October 2, 2008 Share Posted October 2, 2008 could you post the browser source instead it makes it more readable. I assume you have a js error Quote Link to comment Share on other sites More sharing options...
ninedoors Posted October 2, 2008 Author Share Posted October 2, 2008 browser source <tr> <td><script type="text/javascript"> var vals = new Array(1,2,4,3,5,6,7,13,19,22); document.write('<div id="container" class="picker_container" style="width:239px">'); for (ev in vals){ document.write('<div class=box onclick="s(this)">'+vals[ev]+'</div> '); } document.write('</div>'); </script> </td> </tr> IE7 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.