I've got the below script included using a .js file and it won't fire. I'm very new to JQuery and can't see where I'm going wrong.
Help please.
I've now changed the script to the below with the following changes: used Theophilus's example code to amend mine and it now fires correctly thanks Julian $(this).attr(':checked') does not work for me as it returns "unasigned." However using .prop does $(this).prop('checked') works as expected (true/false) thanks Rashet, for testing purposes I changed url to '/my.script.php' which contains a simple testing script and still does not work.
if(isset($_POST['id']) || isset($_POST['Purchased'])){
die('Eureka! variables exist');
}else{
die('Failure!, variables do not exist');
}
$('input[name=Purchased]').change(function(){
//if a checkbox with name 'Purchased' is clicked, do the following.
var id=$(this).attr('id'); //grab the id from the clicked box
var Purchased=$(this).prop('checked');
//alert("ID value:"+id); returns correctly
// alert("Purchase value:"+Purchased); //Returns correctly
//setup the ajax call
//Not posting the variable values to PHP processing script
$.ajax({
type: 'POST',
url: '/my.script.php',
data: {id: 'id',
Purchased: 'Purchased'}
});
});