[Javascript] Checkbox challenge

Shawn Milo milo at linuxmail.org
Fri May 7 07:19:05 CDT 2004


----- Original Message -----
From: <dev at qroute.net>
Date: Thu, 6 May 2004 16:58:35 -0700
To: "[JavaScript List]" <javascript at LaTech.edu>
Subject: Re: [Javascript] Checkbox challenge

> I did it this way; it worked. Thank you guys !...
> 
> <script>
> function  CheckMax(maxNo,obj)
> {
>  var numChecked = 0
> 
>  var bolPop=false;
>  for(var x = 0; x < obj.length; x++){
>   if(obj[x].checked){
>    numChecked++
>    if (numChecked>=maxNo) {
>     bolPop=true
>     obj[x].checked=false
>    }
>   }
>  }
> 
>  if (bolPop)
>  {
>   alert('You have already selected '+maxNo+' items. ')
>  }
> 
>  return true;
> }
> </script>

<snip>

If it works, it works.  But personally, I would avoid 
the extra variable.  If you already have 'numChecked', 
why not just use that as your test for whether you
should pop up the 'alert' box?

Shawn



More information about the Javascript mailing list