Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form | Q1247 [ previous next ]

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

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'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.