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>