Need some help working with checkboxes..
Looking how to put some sort of check so that if two checkboxes within the same ul are checked, at least once anywhere on the page, button "Two" does not get enabled.. I probably need to have some sort of loop checking each ul maybe?? I have cut the code down to a bare minimum, but there are many ul being created on the page dynamically.. Not just two like in this example.. Here is sample script..
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script>
- $('input.choice').live('click', function(){
- if ($('input.choice:checkbox:checked').length > 0) {
- $('#one').attr('disabled', '');
- if ($('input.choice:checkbox:checked').length > 1) {
- // if two checkboxes are checked in the same ul,
- // disable button "Two", else enable button "Two"
- $('#two').attr('disabled', '');
- } else {
- $('#two').attr('disabled', 'disabled');
- }
- } else {
- $('#one').attr('disabled', 'disabled');
- $('#two').attr('disabled', 'disabled');
- }
- });
- </script>
- List One
- <ul>
- <li class="one"><input type="checkbox" class="choice" /></li>
- <li class="one"><input type="checkbox" class="choice" /></li>
- </ul>
- List Two
- <ul>
- <li class="one"><input type="checkbox" class="choice" /></li>
- <li class="one"><input type="checkbox" class="choice" /></li>
- </ul>
- <input type="submit" value="One" id="one" disabled="disabled" />
- <input type="submit" value="Two" id="two" disabled="disabled" />