Jump to content

Help with check boxes?


Recommended Posts

Right now I have this code running to actively count how many check boxes are checked actively on a page.

They're are about 20 check boxes, but I want to be able to say after 8 are checked, don't allow anymore to be checked. (Restrict them) BUT... still be able to uncheck them incase you want to change one.

Say like:

[x] 1

[x] 2

[x] 3

[x] 4

[x] 5

[ ] 6

[x] 7

[x] 8

[x] 9

[ ] 10

[ ] 11

[ ] 12

Ok, that's 8 checked, so I can't check number 11.... But if I uncheck any of the ones that are checked, then I can.

How do I do this?

Here's my code that's counting:

<script language="javascript">

function countChecked() {
var n = $("input:checked").length;
$(".remain").text(8 - n + (n === 7 ? " item" : " items") + " remaining!");
if (n ==  alert("I am an alert box!");
}
countChecked();
$(":checkbox").click(countChecked);

</script>

EDIT: JUST kidding.. I got it:

var checkedcount=0

for (var i=0; i<checkgroup.length; i++)

checkedcount+=(checkgroup.checked)? 1 : 0

if (checkedcount>limit){

this.checked=false

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Who's Online   0 Members, 0 Anonymous, 1065 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...