Let us consider we have a js array as
scriptAr = new Array();
scriptAr = "one";
scriptAr = "two";
scriptAr = "three";
Now we will create a hidden form field as follows
<form action="phpArrayTest.php" method=post name=test onSubmit=setValue()>
<input name=arv type=hidden>
Here what we have done is, when the submit is called we first do some work ("onSubmit=setValue()") by using the onSubmit method. The onSubmit method will invoke setValue() function defined by us. After that the action will take place and stringTokens.php will be called.Step 3:
Here we define the setValue method. The method will convert the array periviously defined in to a string and then set it to the hidden field.
var arv = scriptAr.toString();
// This line converts js array to String document.test.arv.value=arv;
// This sets the string to the hidden form field. }
In the php file the string will be split back into array.