Dynamically created checkbox

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
tolearn
Forum Newbie
Posts: 9
Joined: Wed Nov 29, 2006 5:27 am

Dynamically created checkbox

Post 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?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Have you tested it out?
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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++;
}
Post Reply