Copy link to clipboard
Copied
Hi everyone, kinda new to Java and trying to build a form for my job for leave requests. My issue is that I am trying to assign a variable a value whether one radio button or another is clicked. Currently they are mutually exclusive with the following information:
Name: Radio
Tooltip: Choice
Button Style: Check
Radio Button Choice: Yes (this is the export value I believe though I don't quite know how to use it properly)
neither are checked by default but if one is checked I would like to have a variable set to the text "Approved" and if the other radio button is checked I would like to set the variable to contain "Disapproved"
Here is my code currently and thanks in advance for the help to all:
var S_auth;
function auth() {
if (Radio.value == "Yes") {
var S_auth = "Approved";
}
else {
var S_auth = "Disapproved";
}
}
var Employee = this.getField("Emp_Name").value;
var Supervisor = this.getField("Supervisor").value;
var Leave_Type = this.getField("Dropdown2").value;
var cToAddr = name@emailaddy.com;
var cCCADDr = this.getField("Email").value;
var cBenAddr = this.getField("Sup_Email").value; if (cBenAddr != "") cCCADDr += ";" + cBenAddr;
var cSubline = "Re: Leave request form for" + " " + Employee + ", " + Leave_Type + ", Status: " + S_auth;
var cBody = "Your leave request has been " + S_auth + " by " + Supervisor.\n" + "Save mail attachment for your records.\n";
this.mailDoc({
bUI: true,
cTo: cToAddr,
cCc: cCCAddr,
cSubject: cSubLine,
cMsg: cBody
});
I honestly just want to have the subject line and body to be able to show approved or disapproved depending on which radio button the supervisor selects.
Yes, your script is correct now and should work.
Copy link to clipboard
Copied
if ( this.getField("Radio").value=="Yes") {
S_auth = "Approved";
} else S_auth = "Disapproved";
I'm home from work and have been looking around but if anyone knows, will this work? I'm going to try it in the morning
Copy link to clipboard
Copied
Yes, your script is correct now and should work.
Copy link to clipboard
Copied
When I press the submit button to create the email it still says the variable S_auth is undefined, is there something I did wrong? I did what I wrote above and then tried this afterward and both of them state the variable is undefined:
First time:
var S_auth;
function auth() {
if(this.getField("Radio").value == "Yes") {
S_auth = "Approved";
}
else { S_auth = "Disapproved";
}
}
Second time:
var Rad = this.getField("Radio").value;
var S_auth;
function auth() {
if(Rad == "Yes") {
var S_auth = "Approved";
}
else {S_auth = "Disapproved";
}
}
Now both times the variable S_auth gets printed as "undefined", is there something I'm doing wrong in getting the proper text to that variable?
Copy link to clipboard
Copied
Anoop9178, I figured it out...for some reason Acrobat's Javascript doesn't like the function and once I took that out and just used the if statement it worked perfectly. Thanks
Copy link to clipboard
Copied
Is there a way to do this with Radio buttons too? I tried the following, but when I do and fill out the form with one of the radio buttons listed, it keeps displaying the fields (all required even if there is a response) and thinks they are missing.
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off") || (f.type=="Radio" && f.value=="Off"))
f.strokeColor = color.red; //Highlights the required fields in red
emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
else app.execMenuItem("Print");
Copy link to clipboard
Copied
The code above does check the values of radio-buttons.
Copy link to clipboard
Copied
Ok. What I am finding though is that regardless if one of the radio button values are selected, the code is still coming up as requiring an answer for that particular required field. It doesn't seem to be working as intended.
Copy link to clipboard
Copied
I see the problem now. You used the wrong type value. It needs to be:
f.type=="radiobutton"
Not:
f.type=="Radio"
Copy link to clipboard
Copied
Thanks. Something else appears to be wrong. It seems even if I enter a response into one of the required radio buttons, it is still mentioning that specific required field by name, even if they have a response. Also, it is not allowing the printing piece. Your assistance with troubleshooting is very greatly appreciated.
Copy link to clipboard
Copied
Can you share the actual file (via Dropbox, Google Drive, etc.)?
Copy link to clipboard
Copied
Sure, you can see it here: https://dl.dropboxusercontent.com/u/18645159/IPR-090716-FINAL.pdf
I've attached the Javascript to the Print button (right now) on page 1. Ideally, it would be on each Print Button on all pages.
Copy link to clipboard
Copied
How did you create the fields in this file?
On Wed, Sep 28, 2016 at 9:49 PM, matthewjcook15 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Adobe DC
Matt
Copy link to clipboard
Copied
Strange... Something is wrong with them, but the script will still work, if adjusted slightly.
Try this version: IPR-090716-FINAL_edited.pdf - Google Drive
Copy link to clipboard
Copied
Thank you for your help. Here is the final code that worked.
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off") || (f.type=="radiobutton" && f.value=="Off")) {
f.strokeColor = color.red; //Highlights the required fields in red
emptyFields.push(f.name);
}
}
}
if (emptyFields.length>0) {
app.alert("Sorry! You must fill in the following fields prior to printing:\n" + emptyFields.join("\n"));
}
else { app.execMenuItem("Print");
}