...

View Full Version : Passing values from one form to another query.



ramki067
03-03-2008, 05:11 AM
Hi,
I'm passing the checkboxes which are clicked to the next form. But if i click the checkboxes and submit it the values are not reflected in the next form. But if i go back and refresh the page using F5 and then click the checkboxes and click Submit the values are passed to next form! What could be the reason for this? Please help.

Thanks,
Ramki.



foreach($lines as $line_num => $line)
{
preg_match('/\t([-\w]+)[^\t]*\t([-\w]+)/', $line, $matches);
echo "<font size=3><tr bgcolor=$bgc><td>$j</td>";
echo "<td>$matches[1]</td>";
$streams[$k]= $matches[1];
if($matches[1]!="")
{
$stream_lines[$k]=$line;
}
echo "<td><center><input name=\"sstreamname\" type=\"checkbox\" onclick=\"check();\"></center></td></tr></font></center></tr></font></center>";
$j++;
$k++;
}




The below is the javascript function:



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

}
document.getElementById('ParrStr').value=ParrStr;

}

Fou-Lu
03-03-2008, 07:50 PM
If this:


foreach($lines as $line_num => $line)
{
preg_match('/\t([-\w]+)[^\t]*\t([-\w]+)/', $line, $matches);
echo "<font size=3><tr bgcolor=$bgc><td>$j</td>";
echo "<td>$matches[1]</td>";
$streams[$k]= $matches[1];
if($matches[1]!="")
{
$stream_lines[$k]=$line;
}
echo "<td><center><input name=\"sstreamname\" type=\"checkbox\" onclick=\"check();\"></center></td></tr></font></center></tr></font></center>";
$j++;
$k++;
}

correctly generates the checkboxes, this is not the problem. What I can tell you is it has no idea what checkbox its currently selected at, you need to add a value to actually get the number. If I'm not mistaken, I believe that the checkboxes fallback on numerical indicies, but that you would have to confirm with an html specialist.
So, with that out of the way, it is likely your js causing problems.


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

}
document.getElementById('ParrStr').value=ParrStr;

}

I'm not a JS kinda guy, but where is document.forms.stream_selection? Perhaps that is to be sstreamname? J is also seeking a magic number (<1000), instead, you should run that against the length of the checkbox array: frm.length() if I'm not mistaken. This will also let you ignore the check for null, as it has to exist in the array.
Hope that helps, and hopefully its something as simple as that!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum