I have found a solution of sorts, though I am sure it is less glamourous than it could possibly be.
I just got PHP to set a hidden field called rowCount to tell me how many checkboxes and listboxes there are in the format of checkboxes,listboxes.
I then call the following on the onClick event of the checkboxes.
Code: Select all
function refreshZoneList(control) {
var index = parseInt(control.name.substring(control.name.indexOf("ї") + 1, control.name.length - 1))
var currform = control.form;
var params = currform.rowCount.value.split(",")
var checkVal
// Find the correct listbox
if(parseInt(paramsї1]) == 1) {
// there is only one of this control, access it directly
var targetList = currform.newRow
var startPoint = 0;
var endPoint = parseInt(currform.newRow.name.substring(currform.newRow.name.indexOf("ї") + 1, currform.newRow.name.length - 1)) -1
} else {
// loop through to find the next new row after the clicked checkbox
for (i=0; i < parseInt(paramsї1]); i++) {
checkVal = parseInt(currform.newRowїi].name.substring(currform.newRowїi].name.indexOf("ї") + 1, currform.newRowїi].name.length - 1));
var startPoint = 0;
if (index < checkVal) {
var targetList = currform.newRowїi];
var endPoint = checkVal-1;
break;
} else {
var startPoint = i+1;
}
}
}
// Clear the listbox
clearcombo(targetList)
//Get the checkbox values
if (parseInt(paramsї0]) == 1) {
// there is only one of this control, access it directly
if (currform.isSelected.checked) {
targetList.optionsїtargetList.options.length]= new Option("Create Sub-Zone in ...", "0");
targetList.optionsїtargetList.options.length]= new Option(currform.zonename.value, currform.isSelected.value);
}
} else {
// this is a control array, iterate instances between defined start and end points
for (i=startPoint; i < endPoint; i++) {
if (currform.isSelectedїi].checked) {
if (targetList.options.length == 0) {
targetList.optionsїtargetList.options.length]= new Option("Create Sub-Zone in ...", "0");
}
targetList.optionsїtargetList.options.length]= new Option(currform.zonenameїi].value, currform.isSelectedїi].value);
}
}
}
// Check to make sure that the list hasnt been left empty. Pad with value and disable if it is.
if (targetList.options.length == 0) {
targetList.optionsїtargetList.options.length]= new Option("Choose a Primary Zone", "0");
targetList.disabled = true
} else {
targetList.disabled = false
}
// force a refresh of row selection for the targetList so that it gets greyed
setRow(targetList);
}
Is it perfect? I seriously doubt it. But it seems to be working at this point.
If you can see any obvious way to do this a cleaner way, let me know. I'm still trying to wrap my mind around the whole javascript thing, and any tips are appreciated.
Thanks