0

Hello Friends,

I have checkbox which is generated dynamically. Here the code is :

<?php	
	$i=0;
	while($row1 = mysql_fetch_array($result))
	 {?>
		<label><?php echo $i++ ?><input type="checkbox" name="chk_list[]"  value="<?php echo $row1['Veh_id'];?>" class="txt" onClick=""><?php echo $row1['Veh_nm']; ?></input></label></br>
	 		
	<?php  } 
		
		
		
		?>

Now, I want to insert IDs and related information which checkboxes are checked. So, I tried small javascript on button when its clicked.

function validate()
		{
			
			
			var chk = document.frm.chk_list;
			//alert (chk);
			for(i=0; i<chk.length; i++)
			if(chk[i].checked==true){
			alert (chk[i].value);
			}			
			
		}

now thing is how can I access this value in PHP? Is there any trick to pass array from javascript and use them in PHP code??

Thanking You,
Hakoo Desai.

3
Contributors
3
Replies
7
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

if you have placed checkbox chk_list[] in the html <form> element, then you can submit the form with action=some.php.

Now in your php file
you will get array of selected values
$_POST[0]
$_POST[1]
$_POST[2]
.
.
.
.
$_POST[n]

Here n is number of selected check boxes,
Here Unselected checkboxes are not available in the array.

0

You can also use loop for getting its value.

<?
	$chk_list = $_POST['chk_list'];
	foreach($chk_list as $key=>$Veh_id)
	{
		echo '<br />'.$Veh_id.' is checked';
	}
?>
0

Add this code.
This code will print all forms posted data.

if(isset($_POST))
{
    echo '<pre>';
    print_r($_POST);
}

Post your output here.

Edited by vibhaJ: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.