How to Store javascript checkbox result in php mysql -
i trying accomplish live checkbox result checked/unchecked checkbox. logic checkbox works want store live checkbox result in mysql. when click on checkbox, result should stored in database same when uncheck checkbox result should stored in database. don't want use button in example.
here code:
<!doctype html> <html> <head> <meta charset=utf-8 /> <title>js bin</title> <!--[if ie]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script type="text/javascript" > function writeto(object) { var container = document.getelementbyid("container"); if (object.checked) { container.innerhtml = "added " + object.value + " <br />"; } else { container.innerhtml = "removed " + object.value + " <br />"; } } </script> </head> <body> <div id="container"></div> <input type="checkbox" onclick="return writeto(this)" name="check_list" value="appel">apple<br> <input type="checkbox" onclick="return writeto(this)" name="check_list" value="grape">grape<br> <input type="checkbox" onclick="return writeto(this)" name="check_list" value="orange">orange<br> <?php echo $dd= "<script>document.writeln(container.innerhtml);</script>"; require 'database.php'; echo $sql="update scott123.rahul_tbl_users set group1='$dd' dingoid=70001501"; //$sql1=mysql_query($sql); ?> </body> </html>
have writeto function initiate ajax request server performs mysql insert/update query.
you can check current state of checkbox reading "checked" attribute.
if have experience jquery, makes lot of easier implement.
Comments
Post a Comment