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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit Dynamic No of checkboxes 1

Status
Not open for further replies.

struth

Programmer
Aug 26, 2001
114
GB
I want to limit the number of checkboxes a user can check. But they are dynamic checkboxes so a page could end up with 3, 10, 20 checkboxes in it. It takes the number they can check from an asp variable <%=myCheck%>.

Any ideas

Tia Struth

&quot;Away from the actual ... everything is virtual&quot;
 
<script>
function limit(inObj){
allInput = document.getElementsByTagName(&quot;input&quot;)
numAllowed = 5
numFound = 0
for (x=0; x<allInput.length; x++){
if (allInput[x].type == &quot;checkbox&quot;){
if (allInput[x].checked){
numFound ++
}
}
}
if (numFound > numAllowed){
alert(&quot;too many&quot;)
inObj.checked = false
}
}
</script>

<input type=checkbox onClick=&quot;limit(this)&quot;>
<input type=checkbox onClick=&quot;limit(this)&quot;>
<input type=checkbox onClick=&quot;limit(this)&quot;>
<input type=checkbox onClick=&quot;limit(this)&quot;>
<input type=checkbox onClick=&quot;limit(this)&quot;>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Worked a dream!

Many thanks

&quot;Away from the actual ... everything is virtual&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top