Auto-fill a text field with a popup window when a radio button is selected.

Nov 08, 2017

Copy link to clipboard

Copied

I have a button labeled Military.  When a user clicks on that button, I have a window that pops up asking if they're Active Duty, National Guard, or Reservist.  I'm asking them to input a number representing one of the three choices and then another field auto-fills their choice when they click OK.  Otherwise the field is blank.  Here is what I have so far, but nothing is auto-filled into the other field:

var vMil = this.getField("13: Persona");

// Display Response Box
var vMilInfo = app.response("Input the number representing your military status.\n\n1) Active Duty\n2) National Guard\n3) Reservist"," [Box 9 - DESIGNATION OF PERSON]");

switch(vMilInfo){
case "1":
  vMil.value = "A = Active Duty";
  vValidResponse = 1;
  break;
case "2":
  vMil.value = "N = National Guard";
  vValidResponse = 1; 
  break;
case "3":
  vMil.value = "V = Reservist";
  vValidResponse = 1;
  break;
  vMil.value = "";
   }

I'm doing this in Adobe Acrobat PDF form.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

468

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Auto-fill a text field with a popup window when a radio button is selected.

Nov 08, 2017

Copy link to clipboard

Copied

I have a button labeled Military.  When a user clicks on that button, I have a window that pops up asking if they're Active Duty, National Guard, or Reservist.  I'm asking them to input a number representing one of the three choices and then another field auto-fills their choice when they click OK.  Otherwise the field is blank.  Here is what I have so far, but nothing is auto-filled into the other field:

var vMil = this.getField("13: Persona");

// Display Response Box
var vMilInfo = app.response("Input the number representing your military status.\n\n1) Active Duty\n2) National Guard\n3) Reservist"," [Box 9 - DESIGNATION OF PERSON]");

switch(vMilInfo){
case "1":
  vMil.value = "A = Active Duty";
  vValidResponse = 1;
  break;
case "2":
  vMil.value = "N = National Guard";
  vValidResponse = 1; 
  break;
case "3":
  vMil.value = "V = Reservist";
  vValidResponse = 1;
  break;
  vMil.value = "";
   }

I'm doing this in Adobe Acrobat PDF form.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

469

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 08, 2017 0
Nov 08, 2017

Copy link to clipboard

Copied

Why did you add the last line where you're setting the vMil field to an empty string?

Also, why are you changing the value of vValidResponse in each case?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Nov 09, 2017

Copy link to clipboard

Copied

I added the last line because I thought that I was saying there that if the button is not checked, then the other field would be blank.  As for the vValidResponse, I was testing something and just forgot to take those lines out before copying my code here.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2017 0
Nov 09, 2017

Copy link to clipboard

Copied

You should put that line before the switch command, or under the "default" case.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2017 0
Nov 09, 2017

Copy link to clipboard

Copied

Ok, I moved that line "vMil.value = ""; before the switch command and removed the "vValidResponse" command but it still won't auto-fill in the other field.  I want the user to input a 1, 2, or 3 in the window and when they click OK, the other field will auto-fill either A = Active Duty, N = National Guard, or V = Reservist.

I forgot to mention that I'm still a beginner to JS...but you probably guessed that, I'm sure.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2017 0
Nov 09, 2017

Copy link to clipboard

Copied

Check the JS Console (Ctrl+J) for error messages. If there are none, would you be able to share the file (via Dropbox, Google Drive, etc.)?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2017 0
Nov 09, 2017

Copy link to clipboard

Copied

I got it to work.  The text field had some JS in the Custom Calculation Script window. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2017 0
try67 LATEST
Nov 09, 2017

Copy link to clipboard

Copied

Yeah, that might lead to a conflict. Glad to hear you get it to work!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2017 1