Hello,I would like to get check if checkbox is checked or not on button click and Change the form action url according to it, how do it using javascript or jquery?
Right now using this code
if($('#ChangeURL').attr('checked')) {
//some code
}
but not working as needed.
You should use .is(
:checked)
in jQuery code to check if checkbox is checked, so your code will be
if ($('#ChangeURL').is(':checked')) {
//do something here
}
Using jQuery 1.6+
if ($('#ChangeURL').prop('checked')) {
//Checked
}
OR using Javascript checked
property of a checkbox
if(document.getElementById('ChangeURL').checked) {
//Checked Code
} else {
//Note checked
}
Here are the all possible jQuery method to check, Checkbox state
//here changeURL is Id of the element
$('#changeURL').is(":checked")
$('#changeURL').prop('checked')
$('#changeURL')[0].checked
$('#changeURL').get(0).checked
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly