Skip to main content
Participating Frequently
Dec 29, 2017 9:37 PM UTC
Answered

Autofill text box based on radio button choice

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")

}

}

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 2, 2018 7:43 PM UTC

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


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 = "";

19 replies

Thom Parker
Community Expert
Community Expert
Dec 29, 2017 10:09 PM UTC

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

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
Dec 29, 2017 9:49 PM UTC

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

Translate
Participating Frequently
Jan 2, 2018 2:13 PM UTC

PDF

Translate
try67
Community Expert
Community Expert
Jan 2, 2018 4:35 PM UTC

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.

Translate