LyndonOHRC
Programmer
I am ready to validate several inputs just before my action page executes.
On this page I have 14 checkboxes for our most common transaction types. Additionally I have a select that contains the rest of them.
I already have JS functions that makes sure only one checkbox or a dropdown is selected; that all works great.
Now for final validation I need to make sure that one of the checkboxes is selected or one of the, non-blank, rows in the dropdown is selected.
I was hoping not to strictly reference the checkbox names so I could add or edit them later without needing to modify the validation script. Ultimately I’d like to have them in a database maintained by an application administrator.
I used a naming convention hoping there would be a way to loop through them and determine if at least one is checked.
Note: there are other checkboxes on the form, with dissimilar names, that are not involved with this validation.
On this page I have 14 checkboxes for our most common transaction types. Additionally I have a select that contains the rest of them.
I already have JS functions that makes sure only one checkbox or a dropdown is selected; that all works great.
Now for final validation I need to make sure that one of the checkboxes is selected or one of the, non-blank, rows in the dropdown is selected.
I was hoping not to strictly reference the checkbox names so I could add or edit them later without needing to modify the validation script. Ultimately I’d like to have them in a database maintained by an application administrator.
I used a naming convention hoping there would be a way to loop through them and determine if at least one is checked.
Note: there are other checkboxes on the form, with dissimilar names, that are not involved with this validation.
Code:
<form method="post" action="MyActionPage.cfm" onsubmit="return (IsLicenseTypeSelected())">
....way too many html form elements.....
<input type="submit" value="Print Preview"/>
</form>
<script type="text/javascript">
Function IsLicenseTypeSelected()
{
//if dropdown is not blank
if (document.forms['ReceiptForm'].elements['LicenseTypeOther'].selectedIndex > 0)
{
//I would like to loop throught these
//and return true if one of them is checked
//and/or return false if none are checked
//Convention: "document.ReceiptForm.cb*"
document.ReceiptForm.cbOwner;
document.ReceiptForm.cbMutuel;
document.ReceiptForm.cbFingerprint;
document.ReceiptForm.cbTrainer;
document.ReceiptForm.cbFoodSvc;
document.ReceiptForm.cbReplacementBadge;
document.ReceiptForm.cbOwnerTrainer;
document.ReceiptForm.cbSecurity;
document.ReceiptForm.cbSpouse;
document.ReceiptForm.cbJockey;
document.ReceiptForm.cbCleaningSvc;
document.ReceiptForm.cbOther;
document.ReceiptForm.cbGroom;
document.ReceiptForm.cbAdministrative
}
return true;
}
</script>