allow only 1 checkbox to be checked
I have a series of checkboxes which require that only a single checkbox be selected. I used the below javascript to ensure that only 1 box was checked when the form is submitted:
function checkBoxes() {
var checks = 0;
for (var i=0;i<document.getElementById('FORM_ID').elements.length;i++) {
var e = document.getElementById('FORM_ID').elements[i];
if (e.type=='checkbox') {
if (e.checked) {
checks++;
}
}
}
if(checks == 0){
alert('You must select at least one checkbox');
return false;
}else if(checks > 1) {
alert('Please select ONLY one checkbox');
return false;
}
}
It is implemented on the form submit button like this:
onclick="return checkBoxes();"
Comments
- acxkhr
aUeNKK <a href="http://aeoplssibwic.com/">aeoplssibwic</a>, [url=http://ypiqlkpujbgu.com/]ypiqlkpujbgu[/url], [link=http://iviyfenpdxtw.com/]iviyfenpdxtw[/link], http://lrzpiwlejymv.com/
- March 15, 2010, 11:13 AM