Forum Moderators: open

Message Too Old, No Replies

problem creating array with php array

array problem php javascript

         

rsmarsha

1:18 pm on Jul 4, 2007 (gmt 0)

10+ Year Member



I have the following code:

<script language="JavaScript">
myarr=new Array()
myarr[0]="Please Select an Address"
</script>
<?php $addresses = array();
?>
<#loop:ordering.addresses#>
<?php $addresses[{*loop.ordering.addresses.count}] = {*ordering.addresses.deliveryCompany};?>
<#/loop#>
<?php $count = count($addresses);?>
<script>
for(x=1;x<="<?php echo $count;?>"; x++)
{
myarr[x]="test <?php echo $addresses["+ x +"];?>"
}
function doIt(objval)
{
document.getElementById("msg").innerHTML=myarr[objval]
}
</script>

I'm trying to create a javascript array from a php array i created earlier. The loop and { variables are a template language with the php cart software i'm using. I've created the php array which is populated fine.

I am then trying to add the php vars to a javascript array. If i change :

myarr[x]="test <?php echo $addresses["+ x +"];?>"

to

myarr[x]="test <?php echo $addresses[1];?>"

or so on, it works fine. I just can't get the line to create the array entry using the count inside $addresses["+ x +"].

Any ideas?

The code it is used it is :

<select name="searchin" onChange="doIt(this.options[this.selectedIndex].value)">
<option value="0">Select an address</option>
<#loop:ordering.addresses#>
<option value="{loop.ordering.addresses.count}">{loop.ordering.addresses.count} - {ordering.addresses.deliveryCompany} - {ordering.addresses.deliveryPostcode}</option>
<#/loop#>
</select>
<div id="msg">Please Select an Address</div>

rsmarsha

2:23 pm on Jul 4, 2007 (gmt 0)

10+ Year Member



Please ignore now, have decided to go with a popout selection due to the amount of addresses on account. :)