I am creating an application where a user can select from a list of checkbox's and their choice will be captured, post, and sent to the database. I have searched many forums none have been successful. Here is the code I have:
$('#chkbxId').on('change', function (e){
var value = $(this).val();
var name = $(this).attr('name');
e.preventDefault();
$.ajax({
type: 'POST',
url: '../php/some.php',
async: true,
data: {
name: value
},
success: function (msg) {
alert('success');
if (msg!='success') {
alert('fail');
}
}
});
});
I have an onchange
event because I do not want a submit button.
Edit: While other post have tried to use ajax and jquery to submit a form without redirection. My inquiry is to do it onchange
through a checkbox
element. My application does not contain a submit button.