?
Solved

submit using checkbox

Posted on 2009-02-11
5
Medium Priority
?
677 Views
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...?
0
Comment
Question by:niurexx
5 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 23613143
I have the same request by in coldfusion
0
 
LVL 2

Expert Comment

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

and then try

Try:
onclick="if(this.checked) this.form.submit();" ..after renaming the submit button!      
0
 
LVL 6

Accepted Solution

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

Open in new window

0
 

Author Comment

by:niurexx
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..
0
 

Author Comment

by:niurexx
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(){
		$.ajax({
			type: "POST",
			url: "submit_data.php",
			data: 	"id=" + document.getElementById("id").value,
			success: function(html){
				$("#response").html(html);
			}
		});
		
		}
	
</script>
<?
 
$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>';
}
?></form>
 
 
 
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

0

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