News:

Wondering if this will always be free?  See why free is better.

Main Menu

Javascript Array to PHP

Started by Tyris, August 02, 2004, 08:19:54 PM

Previous topic - Next topic

Tyris

Whoaaaaa, long time no post...
I need more time -_-

anyway... I've got a small question... that I need answered for my CMS...

how do I send Javascript arrays (with text based keys, so cant be referenced numerically; also are generatated on the fly... so variable length etc) to a php script...
I know I've done it before (tho I might have serialized it then sent it thru...) and I cant remember how I did it.. and I cant seem to find any of the stuff relating to how I did it... =S

Any help would be greatly appreciated :)

Thanx

Jack.R.Abbit™

I didn't think you could do text based keys in JavaScript arrays.  Could be wrong... not a javascript guru in any sense.

[Unknown]

Quote from: Jack.R.Abbit on August 02, 2004, 08:48:04 PM
I didn't think you could do text based keys in JavaScript arrays.  Could be wrong... not a javascript guru in any sense.

var hash = {test: 1, test2: 2};

This is the same as:

var hash;
hash.test = 1;
hash.test2 = 2;

Or:

var hash;
hash["test"] = 1;
hash["test2"] = 2;

Each is, basically, equivalent to the rest.

As far as sending it... you'd have to serialize it into a hidden input.  This could be a pain, but you're going to want to use this syntax of for:

for (var key in hash)
   alert(key + " => " + hash[key]);

-[Unknown]

Tyris

Sweet, thanx [Unknown] (I knew I could count on you :) )
That syntax seems pretty basic... why are you saying it could be a pain...?
And to get it into the hidden input... (I already knew i had to do that :)) I just use an onsubmit="function();" where 'function()' serializes and then 'theInput.value = serialized' kinda thing right?

Again, as usual, you've been a great help :)
* Tyris bows
Thanx!!

Advertisement: