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>
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;
}
}
And then I run this:
[CODE] var parr = serialize(document.getElementById(‘code[]’));
alert(parr);
What comes out is a serialization of an empty array.