Dependent checkbox, do you think this can be simplified more?
Posted
by
Louie Miranda
on Stack Overflow
See other posts from Stack Overflow
or by Louie Miranda
Published on 2012-07-04T03:04:13Z
Indexed on
2012/07/04
3:15 UTC
Read the original article
Hit count: 227
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
© Stack Overflow or respective owner