I have a variable that holds the value of a checked checkbox. I need to pass it to a PHP file as a PHP variable so that I can run a query with it. I was told I could achieve this with AJAX but I have no knowledge on it and very little time. I would really really appreciate some help!
<script>
function checked(){
var chkbxElements = document.getElementsByClassName("checkboxes");
for (element of chkbxElements){
if (element.checked)
return element.value ;
}
return null;
}
var element = checked(); //pass it to a php file
I tried the code below but it doesn't work.
$.ajax({
method: "POST",
url:"file.php",
data: {id: element},
success: function(data){}
})
</script>
<?php
$id = $_POST['id'];
?>