Question : jQuery - AJAX Call when a Checkbox is Checked

Hi Experts,

I would like make an AJAX call with jQuery every time a user checks a ckeckbox element on the page.

I have the code below, can you tell me what else I need in order to complete the code please?

Thank you
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function sendReq(){
	var m = $('maid').attr('value');
	var o = $(this).attr('value');
	alert('m = '+m+' and o = '+o);
	$.ajax({
		type:'POST',
		url:'include/values.php',
		data:'make='+m+'&option='+o
	})
}

Answer : jQuery - AJAX Call when a Checkbox is Checked

Here You go, I hope You'll be able to understand. If not, just ask.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('form input:checkbox').click(function() {
		var m = $('#maid').attr('value');
		var o = $(this).attr('id');
		alert('m = '+m+' and o = '+o);
		
		if($(this).is(':checked')){
		alert("Its checked!");
//			$.ajax({
//				type:'POST',
//				url:'include/values.php',
//				data:'make='+m+'&option='+o
//			});
		}
});
});
</script>
</head>

<body>
<form>
<label class="assOption" for="ck-option-2"><input name="ck-option-2" id="ck-option-2" value="2" type="checkbox">&nbsp;Climate Control</label>
<label class="assOption" for="ck-option-3"><input name="ck-option-3" id="ck-option-3" value="3" type="checkbox">&nbsp;Climate Control 3</label>
</form>       
</body>
</html>
Random Solutions  
 
programming4us programming4us