SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Array

Getting Check box values using array in PHP

Many times we have to display a list of names or records for consideration and out of which user can select any number of records for further action. Here we may not know exactly how many records will be displayed as some time based on different conditions records will be collected from a table. So we can list the records with a checkbox by the side of it and user can select any number of recodes. We will have one unique id associated with each record and that will be used as value of the check box. Here is the code to display a list and then you can select and submit to see the result.

This is a server side solution and we can get the array value using client side JavaScript we can also get the value of the array of checkboxes.
Note that if in your server settings global variables is set to OFF then you have to take care for that.


 John  Mike  Rone
 Mathew  Reid  Simon
 // This is to collect box array value as global_variables is set off in PHP5 by default
$box=$_POST['box'];
while (list ($key,$val) = @each ($box)) {
echo "$val,";
}

echo "<form method=post action=''>";
echo "<table border='0' 
cellspacing='0' style='border-collapse: collapse' width='100' >

<tr bgcolor='#ffffff'>
<td width='25%'><input type=checkbox name=box[] value='John'></td>
<td width='25%'>&nbsp;John</td>
<td width='25%'><input type=checkbox name=box[] value='Mike'></td>
<td width='25%'>&nbsp;Mike</td>
<td width='25%'><input type=checkbox name=box[] value='Rone'></td>
<td width='25%'>&nbsp;Rone</td>
</tr>
<tr bgcolor='#f1f1f1'>
<td width='25%'><input type=checkbox name=box[] value='Mathew'></td>
<td width='25%'>&nbsp;Mathew</td>
<td width='25%'><input type=checkbox name=box[] value='Reid'></td>
<td width='25%'>&nbsp;Reid</td>
<td width='25%'><input type=checkbox name=box[] value='Simon'></td>
<td width='25%'>&nbsp;Simon</td>
</tr>

<tr><td colspan =6 align=center><input type=submit 
value=Select></form></td></tr>
</table>";
In ASP similar script to collect checkbox values of a form is available here.

Number of User Comments : 1


Google+
subhendu18-06-2012
Good one thanks
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer