|
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'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.