Post Checkbox state from HTML (JS) to PHP - Javascript jQuery

Javascript examples for jQuery:Form Checkbox

Description

Post Checkbox state from HTML (JS) to PHP

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>PRUEBA AJAX JS PHP HTML</title> 
 </head> //from  ww w  . j  a  v a  2 s .  c o m
 <body> 
  <h1>prueba</h1> 
  <input type="checkbox" name="switch" id="switch"> 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 
  <script>
$("#switch").change(function ()
    {
        var checkbox = $("#switch");
        $.post("accion.php", {my: checkbox.val()}, function(data){
             $("h1").html(data);
        });
    });
 
      </script>  
 </body>
</html>

Related Tutorials