I am currently working on enhancing the functionality of my ordering form.
- When a checkbox is checked, the quantity dropdown value will change to 1.
- When a checkbox is unchecked, the quantity dropdown value will change to 0.
- If the quantity dropdown value is set to anything other than 0, the checkbox will automatically be checked.
- If the quantity dropdown value is set to 0, then the checkbox will be unchecked.
I have successfully implemented most of these features, however, I am facing an issue with number 4 - the checkbox does not uncheck when the dropdown is set to 0.
Here is the code snippet:
$(document).ready(function() {
$(".product input:checkbox").change(function() {
if ($(this).is(":checked")) {
$(this).siblings("select").val(1);
} else {
$(this).siblings("select").val(0);
}
});
$(".product select").change(function() {
if ($(this).val != '0') {
$(this).siblings("input:checkbox").prop("checked", true);
}else{
$(this).siblings("input:checkbox").prop("checked", false);
}
});
});