I’m trying to switch the var “act” withing my function dynamically. I looks OK, but for some reason I keep on getting the same act whether I check the checkbox or uncheck it… Can someone please take a look and see what I’m missing here?
$(".chkbx").change(function() {
if($(this).attr("checked", true)) {
var act = "remFromSessionSingleID";
} else {
var act = "addToSessionSingleID";
}
SelectedContactsInSession(act, $(this).val());
});
function SelectedContactsInSession(act, id) {
$.ajax({
url: "actions.php",
type: "POST",
data: "op="+act+"&contID="+id
});
}
You’re setting the
checkedattribute totrueby passing it toattr, which then returns a jQuery object (that will always be truthy). Just get the attribute instead:A better way is to use
is: