/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Multidimensional form value array issue

I have a form that I’m trying to some ajax stuff on.

the form looks like this

[CODE]<form name=”multi” action=”multi_code_add.php” method=”post”>
<input type=”text” value=”” name=”code[0][id]” size=”7″>
<input type=”text” value=”” name=”code[0][q]” size=”3″>
<input type=”text” value=”” name=”code[1][id]” size=”7″>
<input type=”text” value=”” name=”code[1][q]” size=”3″>
<form>[/CODE]

I’m trying to serialize the code[] array for use by php.

I have this:

[CODE]function serialize(txt)
{
switch(typeof(txt))
{
case ‘string’:
return ‘s:’+txt.length+’:”‘+txt+'”;’;
case ‘number’:
if(txt>=0 && String(txt).indexOf(‘.’) == -1 && txt < 65536) return ‘i:’+txt+’;’;
return ‘d:’+txt+’;’;
case ‘boolean’:
return ‘b:’+( (txt)?’1′:’0′ )+’;’;
case ‘object’:
var i=0,k,ret=”;

for(k in txt)
{
//alert(isNaN(k));
if(!isNaN(k)) k = Number(k);
ret += serialize(k)+serialize(txt[k]);
i++;
}
return ‘a:’+i+’:{‘+ret+’}’;
default:
return ‘N;’;
alert(‘var undefined: ‘+typeof(txt));return undefined;
}
}
[/CODE]

And then I run this:

[CODE] var parr = serialize(document.getElementById(‘code[]’));
alert(parr);
[/CODE]

What comes out is a serialization of an empty array.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ellisglauthorJan 29.2008 — Never mind - Figured it out - just needed to hard code an array pulling the information from the form..
×

Success!

Help @ellisgl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...