I have some values in a PHP variable that is the address of customer. It is passed into the fieldset in html to show on the page.
<fieldset>
<address><?php echo $_order->getShippingAddress()->getFormated(true) ?></address>
</fieldset>
I want to get each value in the set into a javascript variable. How can I do that?
<?php $_ad = $_order->getShippingAddress()->getFormated(true);?>
I want the values from $_ad into the javascript variable. I have tried to do so but i can only get one index like $_ad[0]. that gives only one alphabet!!!
Here is what I have tried,
val = '<?php echo $_ad[0] ;?>';
Since javascript is evaluated on the client side and php on the server side, there is no direct way to interact or exchange variables.
You can either expose a webservice that you can then access from javascript via an ajax call. Or you could just parse the data from the page, since you know for sure, that there will be a fieldset with a address inside it. Use jQuery and try something like this:
jsFiddle for that