I'm struggling with a weird happening in my most recent code.
I have a dynamic generated list where each line contains a checkbox. My intention is that if checkbox changes and I get a confirmation, my database will be updated.
The thing is, it does work the first time I change. But the following attempts don't. But if I get the page refreshed, it works again the first time I change.
It has to be some javascript stuff.
$(':checkbox').change(function() {
if (confirm("Does the status of this survey really changed?")) {
variable = $(this).val();
$.post( "handler.php", { handler: '18', value: variable}, location.reload());
}
});
PS: Also alerted the 'variable' each time it triggers and the values are changing.
Could you guys please help me solve it out?
Thanks in advance.
EDIT: Thanks a lot for all the answers. What helped me out, besides the understanding of the event delegation, was that it works better with click event. I'm still gonna try to understand what's the point of triggering onchange at onblur but for the moment, keeping onchange didn't help me.