1. Suggestion to improve your code
You have to add the "name" attribute to your in order to run your code as expected:
$("input[name='vehicle']"), submitButt = $("input[name='Submit']");
var checkboxes = $("input[name='vehicle']"),
submitButtList = $("#Submit");
checkboxes.click(function() {
submitButt.attr("disabled", !checkboxes.is(":checked"));
if (!checkboxes.is(":checked")) {
submitButtList.addClass("disabled");
} else {
submitButtList.removeClass("disabled");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car"> I have a car<br>
<input type="submit" name="Submit" value="Submit" disabled>
2. Suggestion to improve Milan Chheda plain javascript code
If you want, you can also use enter link description here First answer with plain javascript in a shorter form:
You can replace:
document.querySelectorAll('input[type="submit"]')[0].disabled = true;
if (checkedOne) {
document.querySelectorAll('input[type="submit"]')[0].disabled = false;
}
with
document.querySelectorAll('input[type="submit"]')[0].disabled = !checkedOne;
function callFunction() {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
var checkedOne = Array.prototype.slice.call(checkboxes).some(x => x.checked);
document.querySelectorAll('input[type="submit"]')[0].disabled = !checkedOne;
}
<input type="checkbox" name="vehicle" onchange="callFunction()" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" onchange="callFunction()" value="Car"> I have a car<br>
<input type="submit" value="Submit" disabled>