Javascript - validate form issues
I am tyring to create a button using javascript that will do the following:
There are 3 signature lines - PO, SPO, Chief. I want the PO line hidden until the button is click and the form is completed.
- Check to make sure the form is complete
- All text fields
- All radio buttons
- Excluding SPO and Chief signature lines
- If the form is not complete - display an error message and what needs completed.
- If the form is complete
- The CHECK FORM button will disappear
- The PO signature line will appear
I've used different lines of code so far with mixed results. I can get parts of it work but not all of it. Once I fix something, there's another issue. Below is the last line of code I was trying to use.
Code is listed below - Any insight is appreciated:
var poSignatureField = this.getField("PO");
var checkFormButton = this.getField("CHECK FORM");
function validateTextFields() {
var textFields = ["Date5_af_date", "Name", "PACTS", "Q1", "Q2", "3text", "4text", "5text", "6text", "10text", "11text", "12text"];
for (var i = 0; i < textFields.length; i++) {
var field = this.getField(textFields[i]);
if (field.value === "" && field.name !== "SPO" && field.name !== "Chief") {
return false;
}
}
return true;
}
function validateRadioButtons() {
var radioButtons = ["Q3", "Q4", "Q6", "Q7", "Q8", "Q9", "Q10"];
for (var i = 0; i < radioButtons.length; i++) {
var radioButton = this.getField(radioButtons[i]);
if (!radioButton.value) {
return false;
}
}
return true;
}
function checkFormButtonClick() {
if (validateTextFields() && validateRadioButtons()) {
checkFormButton.display = display.hidden;
poSignatureField.display = display.visible;
} else {
app.alert("Please complete all required fields before submitting the form.");
}
}
checkFormButton.setAction("MouseUp", checkFormButtonClick);
