Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1247 How can I prevent the user from checking more than x checkboxes

You are here: irt.org | FAQ | JavaScript | Form | Q1247 [ previous next ]

This can be useful in a survey: select the 3 most ....:

<script language="JavaScript"><!--
maxBoxes = 3;
boxesChecked = 0;
function checkIt(theBox) {
   if (boxesChecked+1 > maxBoxes) {
      alert('Max '+maxBoxes);
      return false;
   }
   boxesChecked++
   return true;
}
//--></script>

<form>
<input type="checkbox" onClick="if (this.checked) return checkIt(this); else boxesChecked--">
<input type="checkbox" onClick="if (this.checked) return checkIt(this); else boxesChecked--">
<input type="checkbox" onClick="if (this.checked) return checkIt(this); else boxesChecked--">
<input type="checkbox" onClick="if (this.checked) return checkIt(this); else boxesChecked--">
</form>

Feedback on 'Q1247 How can I prevent the user from checking more than x checkboxes'

©2018 Martin Webb