Forum Moderators: open

Message Too Old, No Replies

Javascript and PHP arrays

Passing a string array from javascript to PHP

         

Riab

2:03 am on Mar 11, 2004 (gmt 0)

10+ Year Member



can u plz tell me how can i pass a string array from javascript to php? Now i am using an array of hidden fields to take values to server while submitting.
like,

<form name="formHid">
<input type="hidden" name="hid1">
<input type="hidden" name="hid1">
</form>

<script language="javascript">
document.formHid.hid1[0].value="SONY";
document.formHid.hid1[0].value="PEPSI";
document.formHid.submit();
</script>

But when i print that array its characters are all separated like if i pass "SONY","PEPSI" from javascript, while printing in php it comes like S,O,N,Y,P,E,P,S,I.

Purple Martin

2:12 am on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The JavaScript looks good, so you need to look at why the php is splitting the strings.

Riab

3:12 am on Mar 11, 2004 (gmt 0)

10+ Year Member



can u plz tell me how can i pass a string array from javascript to php? Now i am using an array of hidden fields to take values to server while submitting.
like,
<form name="formHid">
<input type="hidden" name="hid1">
<input type="hidden" name="hid1">
</form>

<script language="javascript">
document.formHid.hid1[0].value="SONY";
document.formHid.hid1[1].value="PEPSI";
document.formHid.submit();
</script>

But when i print that array its characters are all separated like if i pass "SONY","PEPSI" from javascript, while printing in php it comes like S,O,N,Y,P,E,P,S,I.

i'm trying to print the submitted array in php like this,
<?

for($i=0;$i<2;$i++) print($hid1[$i]);

?>