#1
  1. Super Genius
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Orlando, Florida
    Posts
    314
    Rep Power
    13

    Looking for a JavaScript


    I'm looking for a JavaScript that allows a user to check a limited ammount of checkboxes within a form.

    To better illustrate, I'm creating a content management system that will allow the administrator to set "Spotlight" items for a product catalog. These items will be displayed on the front page of the catalog.

    A quick solution would be to have ten dropdown menus with all the products in the catalog listed in the menu but there are well over 1100+ items and that would be really bad. This also leaves the possiblity for one spotlight item to appear twice.

    Any suggestions?
    Sleep is highly overrated.
  2. #2
  3. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    var iBoxmax = 5; //maximum number allowed

    function boxLimit(oLastbox, iMax) {
    var oEl, e = 0, iChecked = 0, f = document.forms[0];
    var sMsg = '\nYou have exceeded the maximum number of checked items allowed.\n\n';
    sMsg += 'Please deselect checked items before choosing new ones! Thanks.\n\n';
    while (oEl = f.elements[e++]) if (oEl.type == 'checkbox' && oEl.checked) ++iChecked;
    if (iChecked > iMax) {
    alert(sMsg);
    return (oLastbox.checked = false);
    }
    }

    function init_boxLimit() {
    var oEl, e = 0, f = document.forms[0];
    while (oEl = f.elements[e++]) if (oEl.type == 'checkbox')
    oEl.onclick = function() {if (this.checked) boxLimit(this,iBoxmax)};
    }

    onload = init_boxLimit;

    </script>
    </head>
    <body>
    <font color="green">
    <form>
    <input type="checkbox"> item 1<br>
    <input type="checkbox"> item 2<br>
    <input type="checkbox"> item 3<br>
    <input type="checkbox"> item 4<br>
    <input type="checkbox"> item 5<br>
    <input type="checkbox"> item 6<br>
    <input type="checkbox"> item 7<br>
    <input type="checkbox"> item 8<br>
    <input type="checkbox"> item 9<br>
    <input type="checkbox"> item 10<br><br>
    <input type="reset">
    </form>
    </font>
    </body>
    </html>
    Last edited by adios; November 23rd, 2002 at 01:26 PM.
  4. #3
  5. Super Genius
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Orlando, Florida
    Posts
    314
    Rep Power
    13

    Thank you!


    That is just too cool. It's exactly what I was looking for. Thanks a bunch!
    Sleep is highly overrated.

IMN logo majestic logo threadwatch logo seochat tools logo