Keep track of checkboxes checked in one CASE stmt
I want to keep track of checkboxes checked or unchecked in a page that has hundreds of checkboxes. My approach is to name each TD, then capture the name and the checked or unchecked status of each checkbox if it is changed by the user, then record this info in hidden HTML text boxes in the page via Javascript. (The contents of the hidden boxes will be written to the database at the end of the user's session. The page is large, so each change can't be written to the database as it is made because it is too slow.)
This approach works if I use numerous CASE statements as follows:
Sample TD: <td><input type=checkbox name="ABC12345" onClick="ABoxWasClicked(this.name,this.checked);"> </td>
function ABoxWasClicked(MgrAndRptOfBoxChecked,CheckedStatus OfBoxChecked) {
switch(parseFloat(document.Form1.CountOfChanges.va lue)) {
case 0:
document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
document.Form1.MgrChosen1.value=MgrAndRptOfBoxChec ked;
document.Form1.CheckBoxStatus1.value=CheckedStatus OfBoxChecked;
return (false);
case 1:
document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
document.Form1.MgrChosen2.value=MgrAndRptOfBoxChec ked;
document.Form1.CheckBoxStatus2.value=CheckedStatus OfBoxChecked;
return (false);
case 2:
document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
document.Form1.MgrChosen3.value=MgrAndRptOfBoxChec ked;
document.Form1.CheckBoxStatus3.value=CheckedStatus OfBoxChecked;
return (false);
default:
alert("ERROR");
return (false);
}
}
Note how MgrChosen and CheckBoxStatus have to iterate for each case 1,2,3 etcetera, so the info of the checked box will record in a new text box. This results in a huge CASE statement if I am to allow a lot of checkbox changes. My preference would be to use something like:
case 0,1,2,3:
document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
document.Form1.MgrChosen[document.Form1.CountOfChanges.value].value=MgrAndRptOfBoxChecked;
document.Form1.CheckBoxStatus[document.Form1.CountOfChanges.value].value=CheckedStatusOfBoxChecked;
return (false);
That is, one CASE statement that will change based on the nth checkbox checked.
Thank you for your help!
Mark J. Weisberger
__________________
Mark J. Weisberger
|