Home update query when check the checkbox with ajax
Reply: 0

update query when check the checkbox with ajax

user1546
1#
user1546 Published in June 18, 2018, 7:47 am

I have a checkbox. if I check or uncheck the check box then a update query should be run with Ajax call.

If checks the checkbox then 1 should be update and if uncheck then 0 should be update. But it is not working.

Checkbox is:

<input type="checkbox" id="test_done" value="<?php echo $row1['id']; ?>" <?php if(($row1['test_done'])=='1') echo "checked='checked'"; ?> data-toggle="checkbox">

In above $row1['id'] and $row1['test_done'] are columns name, which are coming from another select query.

Ajax Is:

<script type="text/javascript">
  $(document).ready(function(){
    $("#test_done").click(function(){    
    var val = $(this).val();
         if($(this).is(':checked')){
         $.ajax({ type: "POST", 
         url: "test_done.php", 
         data: {val:val,apply:'1'} 

         });
         }
         else
         {
         $.ajax({ type: "POST", 
         url: "test_done.php", 
         data: {val:val,apply:'0'} 

         });

         }
      });
   });
 </script>

test_done.php is:

include_once("connection.php");
if($_POST['apply']=='1')
{
$val = $_POST['val'];   
 mysql_query("update patient_package_details set test_done='1' where id='$val'") or die(mysql_error());
}
else
{
$val = $_POST['val'];   
mysql_query("update patient_package_details set test_done='0' where id='$val'") or die(mysql_error());
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32442 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO