When I check the checkbox for 'Monday', the 'Tuesday' checked status is updated. It works well simultaneously.
But, once I click to check or uncheck 'Tuesday', and if I then check 'Monday', the 'Tuesday' doesn't change status as same as 'Monday' anymore. After checking/unchecking 'Tuesday' it doesn't sync with the 'Monday' checkbox.
$(function() {
// main product upload
$("#monday").change(function(e) {
$("#tuesday").attr("checked", this.checked);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<input type="checkbox" id="monday" name="monday">
<input type="checkbox" id="tuesday" name="tuesday">
Use prop instead of attr.
$(function () {
// main product upload
$( "#monday" ).change(function(e) {
$( "#tuesday" ).prop("checked", this.checked);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Monday: <input type="checkbox" id="monday" name="monday" > <br/>
Tues: <input type="checkbox" id="tuesday" name="tuesday" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With