[Javascript] Multiple Select box problem

Matt Barton javascript at mattbarton.org
Thu Sep 16 04:45:43 CDT 2004


Yeah, should be no problem.  Have a validation function something like:

<script language="javascript">

function validateSelectControl () {
    oSelect = document.getElementById ('idofselectbox');

    var iNumSelected = 0;

    for (var iCount=0; oSelect.options[iCount]; iCount++) {
        if (oSelect.options[iCount].selected == true) {
            iNumSelected ++;
        }
    }

    if (iNumSelected > 7) {
        alert ('Select no more than seven options');
        return false;
    }

    return true;
}

</script>


HTH,

Matt

----- Original Message ----- 
From: "Alan Easton" <alaneaston666 at hotmail.com>
To: <javascript at LaTech.edu>
Sent: Thursday, September 16, 2004 9:46 AM
Subject: [Javascript] Multiple Select box problem


> Hello People,
>
> I have a quick question.
>
> I have a multiple select box, so the user can hold down CTRL and select
many
> items in the select box. Now I only want them to select no more than 7, so
> instead of doing a check server side, when the user submits, is there a
way
> to do a JS check before the form is submitted.
>
> Any help would be appreciated,
>
> Alan...
>
> _________________________________________________________________
> Use MSN Messenger to send music and pics to your friends
> http://www.msn.co.uk/messenger
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
> -- 
> This email has been verified as Virus free
> Virus Protection and more available at http://www.plus.net




More information about the Javascript mailing list