[thelist] JS, counting selected checkboxes
Warden, Matt
mwarden at odyssey-design.com
Mon Jan 22 15:47:31 CST 2001
.jeff,
> in order for this to work you'll need to store the number of items checked
> as well as the pre-defined limit. then, as items are checked you increment
> the count or as items are unchecked you decrement the count. if the count
> surpasses the limit then you throw an alert and set the checkbox back to
> unchecked. here's how i'd handle it:
>
> put this in the <head> of your document:
>
> <script language="JavaScript" type="text/javascript">
> <!--
> var numberChecked = 0;
> var maxAllowed = 10;
>
> function limitChecked(obj)
> {
> numberChecked = (obj.checked) ? numberChecked++ : numberChecked--;
Why are you decrementing the variable numberChecked if the checkbox isn't
checked? Wouldn't it just stay the same, unless the checkbox is checked (in
which case it would increment)?
--
mattwarden
mattwarden.com
More information about the thelist
mailing list