I have rows of "To Do" on a checklist, each row has a "Completed" checkbox. Upon clicking the box with the mouse, the following code runs and correctly posts the information (updates the database to track that the task has been completed):
$(function ()
{
$('[id*="howto_step_complete"]').mousedown(function ()
{
var id = $(this).attr('id');
var howto_used_id = id.substr(id.length - 2);
var howto_step_minutes = $('#howto_step_minutes' + howto_used_id).val();
if (!$(this).is(':checked'))
{
var checked = true;
}
else
{
var checked = false;
}
var value = $('#howto_used_id').val();
if (howto_step_minutes != '')
{
$.post("updateChecklist.php",
{
howto_used_id: howto_used_id,
howto_step_complete: checked,
howto_step_minutes: howto_step_minutes
},
function (data)
{
var obj = jQuery.parseJSON(data);
var howto_used_id_returned = obj.howto_used_id;
var howto_step_complete = obj.howto_step_complete;
alert(howto_step_complete);
});
$(this).trigger("change");
}
else
{
alert('Minutes must be filled out before checking complete');
}
});
});
The problem is, if a person uses tabs to move around the form and then uses the spacebar to check the box instead, this isn't triggered, as it's using mousedown. I tried changing this to change()
instead but then my alert box keeps coming up over and over again with "false".
It should be true since I've just checked the box and I don't understand why it continually comes up.
What can I use instead of mousedown()
to get this code to post properly?