Copy link to clipboard
Copied
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.
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);
Copy link to clipboard
Copied
Try this:
var poSignatureField = this.getField("PO");
var tf = false, rb = false;
var textFields = ["Date5_af_date", "Name", "PACTS", "Q1", "Q2", "3text", "4text", "5text", "6text", "10text", "11text", "12text"];
var radioButtons = ["Q3", "Q4", "Q6", "Q7", "Q8", "Q9", "Q10"];
for (var i in textFields) {
if(this.getField(textFields[i]).valueAsString === "")
tf = true;}
for (var j in radioButtons){
if(this.getField(radioButtons[j]).valueAsString === "Off")
rb = true;}
if(tf == false && rb == false){
event.target.display = display.hidden;
poSignatureField.display = display.visible;}
else
app.alert("Please complete all required fields before submitting the form.");
Copy link to clipboard
Copied
in the future, to find the best place to post your message, use the list here, https://community.adobe.com/
p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.
<"moved from using the community">
Copy link to clipboard
Copied
Noted. Thanks.
Copy link to clipboard
Copied
you're welcome. your post is now in the acrobat forum, https://community.adobe.com/t5/acrobat-discussions/javascript-validate-form-issues/m-p/14234281#M438...
Copy link to clipboard
Copied
The following line makes no sense:
if (!radioButton.value) {
A radio button has always a value.
Copy link to clipboard
Copied
Nor this part, since those names don't appear in the array in the first place:
&& field.name !== "SPO" && field.name !== "Chief"
Copy link to clipboard
Copied
I should have mentioned this was my first time really trying javascript. I looked at a lot of adobe forums and tried different things. I also only discovered this morning that I had to enable the javascript debugger in adobe. Which I was not aware it existed until I was watching a video last night on youtube.
Copy link to clipboard
Copied
Try this:
var poSignatureField = this.getField("PO");
var tf = false, rb = false;
var textFields = ["Date5_af_date", "Name", "PACTS", "Q1", "Q2", "3text", "4text", "5text", "6text", "10text", "11text", "12text"];
var radioButtons = ["Q3", "Q4", "Q6", "Q7", "Q8", "Q9", "Q10"];
for (var i in textFields) {
if(this.getField(textFields[i]).valueAsString === "")
tf = true;}
for (var j in radioButtons){
if(this.getField(radioButtons[j]).valueAsString === "Off")
rb = true;}
if(tf == false && rb == false){
event.target.display = display.hidden;
poSignatureField.display = display.visible;}
else
app.alert("Please complete all required fields before submitting the form.");
Copy link to clipboard
Copied
It works! Thanks!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more