I use the following code on jsfiddle.net and the live preview works. Run my own local copy, and nothing…
Checkboxes should change on radiobutton click.
jsfiddle preview: http://jsfiddle.net/XqFDN/
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" ></script>
<script>
jQuery('#3day').click(function () {
jQuery('#mon , #tue , #wed').attr('checked', true);
});
jQuery('#2day , #1day').click(function () {
jQuery('#mon , #tue , #wed').attr('checked', false);
});
</script>
</head>
<body>
<form>
<input type="radio" name="passes" value="3day" id="3day" />3-Day
<input type="radio" name="passes" value="2day" id="2day" />2-Day
<input type="radio" name="passes" value="1day" id="1day" />1-Day
<br />
<input type="checkbox" name="mon" value="mon" id="mon" />Mon
<input type="checkbox" name="tue" value="tue" id="tue" />Tue
<input type="checkbox" name="wed" value="wed" id="wed" />Wed
<br />
</form>
</body>
</html>
You need to wrap your jQuery code in a document ready handler. Try this:
This enclosure ensures that the code within it is run when the DOM has been loaded. Currently, your code is trying to attach
clickevents to elements which do not yet exist.