9lessons programming blog
Loading Search
Friday, March 13, 2009

Submit Checkbox values in Form with javascript

This post explains how to submit Check box values in form. Example mail-box selected mails deletion. I had experimented with javascript support.

In this script Checkbox values store in hidden field name store_del. In demo it was a text field.


Download Script     Live Demo

Html/PHP code.
Here you have to modify SQL Statement.

<form action="submit.php"


onSubmit="return validate()" method="post">


<input type="hidden" id="st_val" name="store_del">


<input type="submit" value=" Submit " >

</form>
<form>
<table><tr><td>
<input type='checkbox' id="ch_all" name='checkbox'
onClick="if(this.checked)checkAll(); else clearAll()" />
</td>
<td><b>9lessons | Tutorials</b></td>
</tr>
<?php
$sql=mysql_query("some SQL statement");
while($row=mysql_fetch_array($sql))
{
$id=$row['user_id'];
$message=$row['message'];
?>
<tr><td>
<input type='checkbox' name='check_del' onclick='test()'
value='<?php echo $id; ?>' />
</td><td> <?php echo $message; ?> </td></tr>
<?php } ?>
</table></form>

Explode! Comma(,) php script
Watch demo 'store_del' value split Comma with below PHP fucntion

<?php

if(isset($_POST))
{
$st_val = $_POST['store_del'];
$store_del_exp = explode("," ,$st_val);
echo $store_del_exp;
$store_del_exp_count=count($store_del_exp); for($j=0; $j<$store_del_exp_count;$j++)
{
$t_id = trim($store_del_exp[$j]);
echo $t_id;
}
}

?>
Download Script     Live Demo
Sponsored Links

Share this post

Comments
{ 3 comments }
Prasad said...

Dear Srinivas,

If we are going to delete the selected records, how to display the new results after submit without refreshing the whole page?

Thanks

adreae said...

can this work without the tags?

Anonymous said...

when we click on submit button why a word "Array" comes in result...????

Post a Comment

Subscribe now!Recent Posts

Categories

Subscribe now!Popular Posts

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine

Like Me

follow me
products

9lessons labs

9lessons clouds

Android application

Chrome Extension