Jump to content

Quick question (array passing from PHP).


Ninjakreborn

Recommended Posts

I have done this before without a problem.  I need to take an array within PHP and pass it into Javascript.  I am using EXTJS library..with it's filter grids.  About 3 of my "fields" need a list of selectable items from filtering and those options are dynamically passed via PHP into javascript.  As far as I was aware there are 2 ways to do this and I have done both successfully so far on multiple occassions.

1. Get the array ready in PHP.  Turn it into JSON and send it to the page.  Then grab the JSON string with javascript and decode it.

2. Just simply pass the array into Javascript. 

 

I have done both methods but the following code is returning strange results:

var subarealist = '{{$subareas}}';
var x;
var subareastring = '';
for (x in subarealist) {
	alert(subarealist[x]);
	subareastring += subarealist[x] + ', ';
}

That is just a snippet from my overall code.  (I am using a modified version of smarty for this project so you'll notice {{$variable}} instead of {$variable}.

In this it's suppos to

* Create subarealist var which has the array put into it (I have done it this way before).

* Create an empty x variable which will be auto-incrementing in the for/in loop.

* Create subareastring variable that's empty to store the final string.

* Look through array and grab the data and put it into the string in the required format.

 

After that I try alerting subareastring...instead of returning what I need it ends up returning half written function calls INSIDE of that variable.  Also if I alert each time the for/in loop goes through like alert(subarealist[x]) it ends up just alerting parts of function calls (one's I have never seen on top of that).  IT's very strange behaviour and any advice would be greatly appreciated.

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.