• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Autofill text box based on radio button choice

New Here ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

We have tried a variety of methods and javascript and absolutely nothing will work. Ideas and help are greatly appreciated!

Here are two codes we tried with no luck:

var A = this.getfield("Group16").value;

var Y = this.getfield("Text21").value;

var Z = this.getfield("Text22").value;

if (A=="Choice1")

document.getElementById("Text27").value = Y;

else document.getElementById("Text27").value = Z;

document.getElementById("Text27").value=this.getElementById("Group16").value;

#2:

var S = this.getfield("Text21").value;

var T = this.getfield("Text26").value;

{

if(Group16.value=="Choice1"){

var S=this.getfield("Text21")

}

else{

var S=this.getfield("Text26")

}

}

TOPICS
Acrobat SDK and JavaScript

Views

3.2K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 02, 2018 Jan 02, 2018

OK. Then use this code as the custom calculation script of "Text3":

var a = this.getField("Group16").valueAsString;

var b = this.getField("Text1").valueAsString;

var c = this.getField("Text2").valueAsString;

if (a=="Choice 1") event.value = b;

else if (a=="Choice 2") event.value = c;

else event.value = "";

Likes

Translate

Translate
Community Expert ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

Is this code for a PDF file or an HTML file?

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
community guidelines
New Here ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

PDF

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
community guidelines
Community Expert ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

OK. Then you're in the right place, but you're quite far away from viable code. Your first code is for HTML pages, so don't bother with it.

I recommend you spend some time studying the correct syntax from Acrobat JS and then try again, or at least provide a better explanation of what you want to achieve.

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
community guidelines
New Here ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

Ok, thank you. That is good to know. I am very new to javascript.

What we are trying to do is in an fillable form, we want the applicant to choose "Choice 1" or "Choice 2" using radio buttons. Once they have selected their choice, we want that radio button to pull a value from a different text field (i.e Text1) and put that value in a third text box (i.e Text3). The idea is if the applicant chooses Choice 1 it will pull the value from Text1 and put it in Text3. If they choose Choice 2 it will pull the value from Text2 and put it in Text3. Does that make sense?

Thanks again for the help!

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
community guidelines
Community Expert ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

Should Text3 be editable by the user, or should its value be determined only by the radio-button (and other text field)?

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
community guidelines
New Here ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

It should not be editable. The value should be determined only by the radio-button.

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
community guidelines
Community Expert ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

OK. Then use this code as the custom calculation script of "Text3":

var a = this.getField("Group16").valueAsString;

var b = this.getField("Text1").valueAsString;

var c = this.getField("Text2").valueAsString;

if (a=="Choice 1") event.value = b;

else if (a=="Choice 2") event.value = c;

else event.value = "";

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
community guidelines
New Here ,
Jan 02, 2018 Jan 02, 2018

Copy link to clipboard

Copied

That worked! Thank you so much! It is greatly appreciated!!!

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
community guidelines
New Here ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

I am trying to accomplish something very similar to my PDF form. In my form, I have a set of Radio buttons; Choice 1 is "Full Service," Choice 2 is "Half Service." Then I have a set of radio buttons for "Once, Twice, or Three days a week." Depending on the results, "service" and "days," I would like this to autofill a number from a text field (rate chart). Can you help with this?

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
community guidelines
Community Expert ,
Mar 10, 2020 Mar 10, 2020

Copy link to clipboard

Copied

First, do a little searching on this forum. This exact question has been answered many times. Ohh, like right here in this thread.  

 

Next, please start a new topic.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
New Here ,
Mar 11, 2020 Mar 11, 2020

Copy link to clipboard

Copied

Thank you Thom Parker, 

 

I thought I was in the right place. Here is as far as I have been able to get. 

 

var a = this.getField("Group16").valueAsString;

var d = this.getField("Group17").valueAsString;

var h = this.getField("Text8").valueAsString;

var i = this.getField("Text9").valueAsString;

var j = this.getField("Text10").valueAsString;

var k = this.getField("Text11").valueAsString;

var l = this.getField("Text12").valueAsString;

var m = this.getField("Text13").valueAsString;

if (a=="Choice1",d=="Choice1") event.value = h; else

if (a=="Choice1",d=="Choice2") event.value = i;

else if (a=="Choice1",d=="Choice3") event.value = j;

else event.value = "";

if (a=="Choice2",d=="Choice1") event.value = k;

else if (a=="Choice2",d=="Choice2") event.value = l;

else if (a=="Choice2",d=="Choice3") event.value = m; else event.value = "";

 

And this works to a point. I can't get it to recognize "Choice2". Suggestions on what to search for? 

 

Thank you in advance. 

 

 

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
community guidelines
Community Expert ,
Mar 11, 2020 Mar 11, 2020

Copy link to clipboard

Copied

if (a=="Choice1",d=="Choice1") 

 

What is the behavior you are expecting from this "if" condition?

Have you read this article?

https://www.acrobatusers.com/tutorials/conditional-execution/

 

Also watch the video Console Window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
New Here ,
Mar 12, 2020 Mar 12, 2020

Copy link to clipboard

Copied

LATEST

Thank you, that video and article was the precise thing I was looking for. As a designer, I am not the best at code and I would like to get better. I will follow through with more classes and tutorials. 

Thank you again. 

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
community guidelines
Community Expert ,
Dec 29, 2017 Dec 29, 2017

Copy link to clipboard

Copied

If this is for a PDF, then you'll need to learn a bit about PDF forms and the PDF JavaScript model.

See the videos posted here to get you started:

PDF Form Field Scripting Basics - YouTube

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines