Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate that 5 of the 10 checkbox are clicked

Status
Not open for further replies.

TheCandyman

Technical User
Joined
Sep 9, 2002
Messages
761
Location
US
I am trying to find a way to make sure 5 checkboxes are clicked out of 10. I looked though the FAQ and search through this form but didn't find anything like this. It should be possible right?
 
it is very possible and the exact code i'm about to re-post has been posted in the past. you will need to change one of the variables to check for 5 instead of 3.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<html>
<head>
<title>Enabling Certain Amount of Checkboxes</title>

<script language="javascript" type="text/javascript">
<!--

var totalCBs = 0;
var maxChecked = 3;

function keepTrack(c) {
    totalCBs += c.checked ? 1 : -1;
    enableDisable( c.form, totalCBs == maxChecked );
}

function enableDisable(f, b) {
    var e = f.elements;
	for (var i = 0; i < e.length; i++) {
        if (e[i].type == 'checkbox' && !e[i].checked) e[i].disabled = b;
	}
}

-->
</script>

<style type="text/css">

</style>

</head>

<body>

	<form name="f">
		<input type="checkbox" name="cb1" onclick="keepTrack(this);" /> Checkbox 1<br />
		<input type="checkbox" name="cb2" onclick="keepTrack(this);" /> Checkbox 2<br />
		<input type="checkbox" name="cb3" onclick="keepTrack(this);" /> Checkbox 3<br />
		<input type="checkbox" name="cb4" onclick="keepTrack(this);" /> Checkbox 4<br />

		<input type="checkbox" name="cb5" onclick="keepTrack(this);" /> Checkbox 5<br />
		<input type="checkbox" name="cb6" onclick="keepTrack(this);" /> Checkbox 6<br />
		<input type="checkbox" name="cb7" onclick="keepTrack(this);" /> Checkbox 7<br />
	</form>

</body>

</html>



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top