Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Passing values from one form to another query.

    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.

    Code:
    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:

    Code:
    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;
    
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    If this:
    PHP Code:
    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.
    Code:
    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!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •