Reputation: 1637
In my script I'm using .click event. When I click my checkbox, value is sending, but there isn't tick in it. So using jquery I "clicked" checkbox, but there isn't working. There is the code:
$(".checkinput").click(function() {
var id = $(this).attr('id')
var dumpthis = $(this);
var data = "id=" + id;
$.ajax({
type: "POST",
url: "change_achievement.php",
data: data,
success: function()
{
if(dumpthis.attr('checked')
{
dumpthis.attr('checked', true);
}
else
{
dumpthis.attr('checked', false);
}
}
});
return false;
});
Upvotes: 0
Views: 104
Reputation: 13496
That is because you are returning false in the end of your click() handler, this stops the event to effect your checkbox. Try return true; to see if it can solve your issue
Upvotes: 0
Reputation: 82943
You are returning false at the end of the handler obviously the checkbox will never be checked. Remove the statement return false;
from your click handler.
So the handler should now look like:
$(".checkinput").click(function() {
var id = $(this).attr('id')
var dumpthis = $(this);
var data = "id=" + id;
$.ajax({
type: "POST",
url: "change_achievement.php",
data: data,
success: function()
{
if(dumpthis.attr('checked')
{
dumpthis.attr('checked', true);
}
else
{
dumpthis.attr('checked', false);
}
}
});
//######THE STATEMENT BELOW SHOULD BE COMMENTED FOR THE CHECKBOX TO WORK
//return false;
});
Upvotes: 1