Page 1 of 1

Dynamically created checkbox

Posted: Thu Dec 07, 2006 3:10 am
by tolearn
Im having a set of checkboxes in a page created dynamically

Code:

in form page

<input name="item_chk[<?php echo $i; ?>]" type="checkbox" id="item_chk[<?php echo $i; ?>]" value="<?php echo $product_ID; ?>">

This creates checkboxes item_chk[0],item_chk[1] etc.

While submitting in the processing page i have to retrieve the value of the checkbox which is checked

Im trying like this:

i have the total no of check boxes created

Code in processing page

$item_chk =$_POST["item_chk"];

$i=0;
while($i<total)
{
if($item_chk[$i]!="")
{

echo $item_chk[$i];
}
$i++;

Is this correct or how to get the data?

Posted: Thu Dec 07, 2006 3:35 am
by aaronhall
Have you tested it out?

Posted: Thu Dec 07, 2006 11:08 am
by AKA Panama Jack
This works...

Code: Select all

$i=0; 
while($i<total) 
{ 
	$element = "item_chk$i";
	if(!empty($_POST[$element]))
	{
		echo $_POST[$element];
	}
	$i++;
}