PDA

View Full Version : Send array to another page.How?


ramki067
02-22-2008, 09:29 AM
HI,
I have a javascript array which i need to pass to another page and access this array using PHP code. I've written the javascript code but need your help on this to send the array to another page. Am i doing anything wrong?Any ideas?



function check()
{

var frm=document.forms.stream_selection
sel_num = new Array()
for(j=1;j<=1000;j++)
{
if(!frm[j].checked)
{
frm[0].checked=false
}
else
{
sel_num =frm[j].value

Parr = new Array();
for(i=0 ;i<sel_num.length ;i++){
Parr.push(escape(sel_num[i].innerHTML));
}
location.href="selected_streams.php?arr="+Parr

}

var par = new Array();
par = get_paragraphs();

var parString = par.toString();

}

}


Thanks,
Ramki.

Actinia
02-22-2008, 08:15 PM
You will need to convert your array to a string. Use the join function.ParrStr=Parr.join(',');
location.href="selected_streams.php?arr="+ParrStr;This will join the elements of Parr, separating them by commas. Your PHP script can then parse the ParrStr using its split function.

J

ramki067
02-23-2008, 03:59 AM
You will need to convert your array to a string. Use the join function.ParrStr=Parr.join(',');
location.href="selected_streams.php?arr="+ParrStr;This will join the elements of Parr, separating them by commas. Your PHP script can then parse the ParrStr using its split function.

J

Thanks Actinia. But i'm unable to access the array in the next page. Infact, i've even given an alert just before the href line as shown below but the alert never executes. What could be the reason?



function check()
{
alert('1');
var frm=document.forms.stream_selection
sel_num = new Array();
Parr = new Array();
for(j=1;j<=500;j++)
{
if(!frm[j].checked)
{
frm[0].checked=false
}
else
{
Parr.push(j);
}

}
alert('3');
ParrStr=Parr.join(',');
location.href="selected_streams.php?arr="+ParrStr;

}


and in retreiving form my code is :


$sel_numbers=$_POST['arr'];
$sel_num=split(",", $sel_numbers);
//$sel_num = explode(" ", $sel_numbers);

$i=0;
while ($i < count($sel_num))
{
//echo "$all_streams[$i]<br>";
echo "$sel_num[$i]<br>";
$i++;
}


Thanks,
Ramki.