Is there a way to capture the value of a checkbox when it changes and then send that value through Ajax?
I have numerous checkboxes displayed on my HTML page, so I can't simply send all the values every time one changes. I only want to transmit the value of the checkbox that was just changed.
Below is a snippet of my HTML code :
<INPUT type="checkbox" name="cb_redir301" value="post_id_445">
<INPUT type="checkbox" name="cb_redir301" value="post_id_573">
<INPUT type="checkbox" name="cb_redir301" value="post_id_264">
<INPUT type="checkbox" name="cb_redir301" value="post_id_387">
<INPUT type="checkbox" name="cb_redir301" value="post_id_190">
(...)
<INPUT type="checkbox" name="cb_redir301" value="post_id_268">
I attempted to use the following JavaScript to capture and send the value, but it doesn't seem to work, possibly due to the non-uniqueness of the checkbox's name ('cb_redir_301').
$('#redir_selector').change(function(evt) {
$.post(ajaxurl, {
action: 'save_backend_assocs',
nonce: $('#ajax_admin_redir_selector_nonce').text(),
cb_redir301: $(this).is(':checked')
}, function(response) {
});
});
});
How can I instruct JS to only send the value of the checkbox that has been altered?