Jump to content

[SOLVED] Dynamic array


ninedoors

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.