submit using checkbox

Posted on 2009-02-11
Medium Priority
Last Modified: 2012-05-06
i wonder if we can manipulate checkbox into submit button. what i mean i everytime user tick the checkbox, the value of checkbox will be send into database immediately. anyone can show me how to do that...?
Question by:niurexx
LVL 19

Expert Comment

ID: 23613143
I have the same request by in coldfusion

Expert Comment

ID: 23613399
onclick="document.formname.submit();return false;"

and then try

onclick="if(this.checked) this.form.submit();" ..after renaming the submit button!      

Accepted Solution

Fero45 earned 750 total points
ID: 23613424
Try onchange
<input type="checkbox" onchange='submit();'>

Open in new window


Author Comment

ID: 23620958
can someone guide me how to do that...? i need to display list of data from database and i need to create paging.. the paging is not a problem, the prob is i need to create code that use ajax to submit the data when user tick the checkbox without refreshing or changing the page..

Author Comment

ID: 23621183
i've try to use onchange and it seems to be working. but i got a problem. when i tick the checkbox, it will be send on the database but the value became same with the first value of the data. can someone please check my code and make some changes. i dont know how.
form :
<script type="text/javascript">
	function register(){
			type: "POST",
			url: "submit_data.php",
			data: 	"id=" + document.getElementById("id").value,
			success: function(html){
$sql = "SELECT * FROM product"; 
$run = mysql_query ($sql);
?><form action="" method="post"><?
while ($p =  mysql_fetch_array ($run)) {
	echo '<input type=checkbox id=id value='.$p[id].' onChange=register();>'.$p['product_name'].'<br>';
submit_data.php :
    $id        = htmlspecialchars(trim($_POST['id']));
    $addClient  = "INSERT INTO license (title) VALUES ('$id')";
    mysql_query ($addClient) or die(mysql_error());

Open in new window


Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question