It would be easier to do it in jQuery.
$(function () {
$('#business').toggle(
function() {
$('#businesslist .subb').prop('checked', true);
},
function() {
$('#businesslist .sub').prop('checked', false);
}
);
});
ggamble
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 11
Solved Threads: 5
Skill Endorsements: 2
This is jQuery. You can add this code at the bottom of your .aspx page just before the closing </body> tag within a set of <script> tags. However, if you include jQuery, you need to reference the jQuery library, typically in your <head> element, just before the closing </head> tag.
Are you familiar with jQuery?
Otherwise you can do this using asp.net c#, but without some form of JavaScript, you'll have to deal with the postbacks.
JorgeM
Industrious Poster
4,023 posts since Dec 2011
Reputation Points: 297
Solved Threads: 549
Skill Endorsements: 115
Sorry ... what I sent is for a button click. This works like you want I think.
http://jsfiddle.net/GBL4s/1/
<label for="business">
<input type="checkbox" id="business">Business</label>
<div id="businesslist">
<ul style="list-style: none;">
<li>
<label for="chk1">
<input type="checkbox" name="chk1" id="chk1" class="sub" />First</label>
</li>
<li>
<label for="chk2">
<input type="checkbox" name="chk2" id="chk2" class="sub" />Second</label>
</li>
<li>
<label for="chk3">
<input type="checkbox" name="chk3" id="chk3" class="sub" />Third</label>
</li>
<li>
<label for="chk4">
<input type="checkbox" name="chk4" id="chk4" class="sub" />Fourth</label>
</li>
<li>
<label for="chk5">
<input type="checkbox" name="chk5" id="chk5" class="sub" />Fifth</label>
</li>
<li>
<label for="chk6">
<input type="checkbox" name="chk6" id="chk6" class="sub" />Sixth</label>
</li>
<li>
<label for="chk7">
<input type="checkbox" name="chk7" id="chk7" class="sub" />Seventh</label>
</li>
</ul>
</div>
$('#business:checkbox').change(function () {
if ($('#business:checkbox').attr("checked")) $('.sub').attr('checked', 'checked');
else $('.sub').removeAttr('checked');
});
ggamble
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 11
Solved Threads: 5
Skill Endorsements: 2
Post the full html ... minus any content of course.
ggamble
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 11
Solved Threads: 5
Skill Endorsements: 2
ggamble
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 11
Solved Threads: 5
Skill Endorsements: 2
I would suggest placing the reference to jQuery just before the closing </head> element. This will ensure that if any other jQuery code is added on this page, the jQuery library would already be loaded...and most likely the visitor would have already visited a site that is referencing this library so, the browser will load it from cache.
Another technique that is common is to wrap the jQuery block within a ready method.
http://api.jquery.com/ready/
JorgeM
Industrious Poster
4,023 posts since Dec 2011
Reputation Points: 297
Solved Threads: 549
Skill Endorsements: 115
Having the reference at the bottom will allow the page to render completely, before running any scripts that might need running. If I remember correctly, the page will stop rendering, if it encounters a script reference, to only continue when its been cached or ready to use. Something to think about when you have a script heavy page.
But for normal pages top or bottom will work fine.
ggamble
Junior Poster in Training
50 posts since Mar 2006
Reputation Points: 11
Solved Threads: 5
Skill Endorsements: 2
@ggamble- I agree with your suggestion. I generally add scripts down just before the closing </body> tag. However, I generally add the reference to jQuery in the <head> section. I'll do some additional reading based upon your explanation. thanks!
JorgeM
Industrious Poster
4,023 posts since Dec 2011
Reputation Points: 297
Solved Threads: 549
Skill Endorsements: 115