Dependent checkbox, do you think this can be simplified more?
- by Louie Miranda
I have the following code which is working, I was wondering if this can simplified more.
Demo: http://jsfiddle.net/TnpNV/8/
<form name="cbform">
<input type="checkbox" value="1" name="one" id="one" /> one<br />
<input type="checkbox" value="1" name="two" id="two" /> two
</form>?
<script>
$('#one, #two').click(function(event) {
var checked = $(this).is(':checked');
if (checked) {
$('#one').attr('checked', true);
$('#two').attr('checked', true);
}
else {
$('#one').attr('checked', false);
$('#two').attr('checked', false);
}
});
</script>
It's basically a two checkbox that is dependent on each other. Jquery was used to check and uncheck them.
Regards