I am currently working on a jQuery function that retrieves the value from a PHP-generated checkbox and sends it through AJAX. The value being sent is always a single word consisting only of letters. Here is the script I have written:
<script type="text/javascript">
$(document).ready(function() {
$("input:checkbox").on("click", function () {
step = this.value;
//document.getElementById("test").innerHTML = step;
responseArray = [];
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
responseArray = eval("(" + xmlhttp.responseText + ")");
document.getElementById("test").innerHTML = responseArray;
}
}
xmlhttp.open("GET", "checkbox.php?step="+step, true);
xmlhttp.send();
});
});
</script>
However, when executing the above code, I encounter the error "ReferenceError: [this.value] is not defined." It's worth mentioning that [this.value] represents the actual dynamic value based on the selected checkbox. Interestingly, in line 5 of the code snippet, the correct value is displayed in the "test" element when uncommented. This leads me to believe that the issue arises after this point. Even simplifying the checkbox.php file down to its basic form results in the same error.
<?php
$step = $_GET["step"];
echo "[" . $step . "]";
?>