Passing dynamic table row data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Passing dynamic table row data

Post by PhpDog »

I have a html page which is dynamically generated from php. The page contains a form and a table whos rows contain a checkbox whith a name of 'rowx' (where x is an incrementing number).

How can I get the individual values of the ticked checkboxes in the page please when the data is passed via a Get?
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Passing dynamic table row data

Post by Weiry »

If you are ONLY passing the TICKED check boxes through GET and nothing else, you could just loop through the $_GET array on the form submit page.
Or you will have to think about forming them into an array then submitting.

Check out this example of a check box array
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: Passing dynamic table row data

Post by PhpDog »

Many thanks weiry. I really like the array idea.
Much appreciated. :D
hemakumarrr
Forum Newbie
Posts: 7
Joined: Mon Nov 09, 2009 12:42 am

Re: Passing dynamic table row data

Post by hemakumarrr »

If u want to get only checked values means u have to pass the values in javascript

<input type="checkbox" name="chk[]" value="1">
<input type="checkbox" name="chk[]" value="2">
<input type="checkbox" name="chk[]" value="3">
<input type="checkbox" name="chk[]" value="4">
for only checked
<script language="javascript">
function chkval()
{
var chk=document.getElementsByName('chk[]');
var str='';
for(i=0;i<=chk.length-1;i++)
{
if(chk.checked==true)
{
str=str+"chkval[]="+chk.value+"&";
}
}
var url="sample.php?"+str;
window.location=url;
}
</script>
sample.php
<?PHP
$chkval=array(1000);

$i=0;
foreach($_REQUEST['chkval'] as $value)
{
$chkval[$i] = $value;
$i++;
}
?>
that values stored in array $chkval.
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: Passing dynamic table row data

Post by PhpDog »

Very nice. Thanks hemakumarrr.
Post Reply