How to pass jQuery variables to PHP variable?

Ajax can do this. Google it, and check out api.jquery.com and look at the ajax functions, .ajax(), .post(), .get(), .load(), etc.

As for your specific question, here is what you would do:

//Javascript file
$("input[type=checkbox]").click(function () {
   $.post('my_ajax_receiver.php', 'val=" + $(this).val(), function (response) {
      alert(response);
   });
});

//PHP file my_ajax_receiver.php
<?php
   $value = $_POST["val'];
   echo "I got your value! $value";
?>

Leave a Comment