I finally, after weeks of trying, go at least an alert to pop up when too many check boxes are checked.
Issue 1:
I have a checkbox list shortnamed 'measures'
and another hidden field name max_count
my function accepts the the checkbox list field ID and a max_count to set the limit.
CountCheckedBoxesInList($(measures_FieldID),$(max_count))
It works fine if I manually enter the max_count value in the Client Side event of the question as well as the initial javascript
CountCheckedBoxesInList($(measures_FieldID),6)
However, using it with the $(max_count) from the hidden field it doesn't ever fire. I am completely stumped... more stumped than I was getting it to work in the first place
Issue 2
Now, this isn't really an issue, but something I haven't been able to get working. I'd like the function to Un-check (checked = false) the last checked box - but can't seem to get that working.
I had assumed since I am passing the function $(measures_FieldID) that I could use that directly, but it never ever seems to work.
The function:
This is the function, it is a hack of one of the built-in functions and I haven't cleaned it up any. I'm not a java developer, so feel free to recommend any improvements to the code below - I literally just by dumb luck got it working... It is in the javascript file.
function CountCheckedBoxesInList(CheckBoxList,themax) {
var thelimit = Number(themax);
if(thelimit > 0) {
var objChkBoxLst = document.getElementById(CheckBoxList);
if(objChkBoxLst) {
var objChkBoxes = objChkBoxLst.getElementsByTagName('input');
var objChkLabels = objChkBoxLst.getElementsByTagName('label');
var i; var numSum = 0;
for(i=0;i
if(objChkBoxes.checked) {
numSum += 1;
}
}
}
if(numSum <= thelimit)
{
return true;
}
if(numSum > thelimit)
{
alert("You may only select a maximum of " + thelimit + " measures");
}
}
}