Possible Duplicate:
How to check if check box is checked in this example (javascript/jQuery.)
I’ve ran into a problem with my checkboxes. I’m trying to set off an event if the button is clicked differing the action whether it is checked or not checked.
Here’s my code
$(document).ready(function(){
$('.pointBox').click(function(event){
var operator = $(this).find('input').attr('operator');
var pointNum = parseInt($(this).find('input').val());
var pointsFromHtml = $('#newPoints').val();
var currentPoints;
var newPoints;
if(pointsFromHtml.charAt(0) == '+'){
currentPoints = parseInt(pointsFromHtml.substring(1));
} else {
return;
}
switch(operator){
case 'addition':
if(!$(this).attr('checked')){
newPoints = currentPoints + pointNum;
}
if($(this).attr('checked')){
alert();
newPoints = currentPoints - pointNum;
}
break;
case 'subtraction':
newPoints = currentPoints - pointNum;
break;
}
$('#futurePoints').text('+' + newPoints);
$('#newPoints').attr('value', newPoints);
});
});
I apologize for being unclear.. I figured out how to solve the problem.
By changing the operator value when the button is clicked, to subtraction it fixes the problem so that it’s next click will reduce the points. This more than likely won’t help anyone else.. but it did solve the problem.