How to separate an array of checkboxes into groups

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SilverNightFall
    New Member
    • Mar 2012
    • 1

    #1

    How to separate an array of checkboxes into groups

    How would I alert the user if they selected more than one COP1000 and in another instance alert the user if they selected more than one COP 2830. Right now it notifies the user if they selected more than one class.

    Code:
    <script type="text/javascript" charset="utf-8">
    var p = 0;
    $(document).ready(function () {
        $('input:checkbox').click(function () {
            var COP1000 = $(this).attr('data');
            if ($('input:checkbox:is_checked').attr()) {
                p++;
            }
            if (p >= 2) {
                alert('You can only select this class once');
                return false;
            }
        });
    });
    </script>
    Below are checkboxes with data being the name of the class

    Code:
    <input name="class[]" data="COP1000" value="<tr><td>COP1000 <td>8:00AM-9:00AM 
    </td><td>MWF </td><td>Sanford </td><td>3</td></tr>" type="checkbox" class="auto-
    style88"/>
    <input name="class[]" data="COP1000" value="<tr><td>COP1000 <td>11:30AM-12:00PM
    </td><td>TTH </td><td>Altamonte </td><td>3</td></tr>" type="checkbox" class="auto-
    style88" />
    
    <input name="class[]" data="COP2830" value="<tr><td>COP2830 <td>11:00AM-12:00PM 
    </td><td>MWF </td><td>Sanford </td><td>3</td></tr>" type="checkbox" class="auto-
    style88"/>
    <input name="class[]" data="COP2830" value="<tr><td>COP2830 <td>6:00PM-8:45PM 
    </td><td>T </td><td>Altamonte </td><td>3</td></tr>" type="checkbox" class="auto-
    style88"/>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    make it a radio button with a single name for each group that should be unique.

    note: HTML code (i.e. the < and > of the HTML tags) are not allowed as attribute value.

    Comment

    Working...