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

Radio button selection to render text

Explorer ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

The attached screenshot should better explain what I am trying to accomplish. I have two radio buttons (boxes) and I need the selected box to render the specified text. Hopefully it is acceptable to communicate what I'm trying to do in the attached image. Thank you in advance for helping this newbie!

TOPICS
JavaScript , PDF forms

Views

1.5K

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 , Aug 18, 2021 Aug 18, 2021

Hi,

 

Assuming that is the only two values you have you can have the code be something like

 

event.value = this.getField("Group1").valueAsString == "INNITIAL" ? "INNITIAL" : "SUP";

 

Draw back with this is that is would put SUP in even if the radio button has not been selected, if that is a problem you can just split it out

 

var radioValue = this.getField("Group1").valueAsString

if (radioValue == "INNITIAL"){

    event.value = "INNITIAL;

} else if ( radioValue == "SUP") {

    event.value = "SU

...

Votes

Translate

Translate
Explorer ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Updated screenshot attached. Thank you.

Votes

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Are radio buttons belong to same group or they are individual?

Lets say they are called "Group1", and that you set buttons choice to be "INNITIAL" and in second button "SUP", use this code:

event.value = this.getField("Group1").valueAsString == "INNITIAL" ? "INNITIAL" : "";

Just replace "INNITIAL" with "SUP" in second text box and change field name if needed.

Votes

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
Explorer ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Thank you Nesa. I'm making progress but not quite there yet. To answer your question, yes the two radio buttons belong to the same group called "Report Type". Do the export values have to export to two seperate text boxes or can the values be rendered in one text box (this is my preference) with the value rendered being "INITIAL" when that box is checked or "SUP" when that box is checked? The attached image shows a rough draft of how I'm understaning currently but obviously I'm off somewhere. Does the code just need to be re-written in one text box to accomodate this? Much appreciated.

Votes

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 ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Hi,

 

Assuming that is the only two values you have you can have the code be something like

 

event.value = this.getField("Group1").valueAsString == "INNITIAL" ? "INNITIAL" : "SUP";

 

Draw back with this is that is would put SUP in even if the radio button has not been selected, if that is a problem you can just split it out

 

var radioValue = this.getField("Group1").valueAsString

if (radioValue == "INNITIAL"){

    event.value = "INNITIAL;

} else if ( radioValue == "SUP") {

    event.value = "SUP"

} else {

   event.value = "";

}

 

This could probably be neatened up, but I wanted to keep it obvious as to what was happening.

 

Votes

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
Explorer ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Thank you BarlaeDC. Unfortunately you're dealing with a newbie. I like the idea of your second scenario. Can you take a look at the error I'm getting and determine what isn't working. Much appreciated! See attachment please.

Votes

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 ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

You are missing " next to second INITIAL.

EDIT:

If you set radio button choices, you can use this:

var radioValue = this.getField("Report Type").valueAsString;
if (radioValue != "Off")
event.value = radioValue;
else event.value = "";

Votes

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
Explorer ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Thank you Nesa. Where do I place this last suggested script in your existing script? Much appreciated!

Votes

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
Explorer ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Actually how do I add your suggestion to the below script I meant to say?:

var radioValue = this.getField("Group1").valueAsString

if (radioValue == "INNITIAL"){

    event.value = "INNITIAL;

} else if ( radioValue == "SUP") {

    event.value = "SUP"

} else {

   event.value = "";

}

Votes

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 ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Sorry I didn't mean to confuse you, you don't need to add it to your script because it does same thing as your script only it's more compact.

Votes

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
Explorer ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Hi BarlaeDC. So when you mentioned "draw back with this is that it would put SUP in even if the radio button has not been selected, if that is a problem you can just split it out".  I am experiencing that behavior as you said. How can I split it out? I am a newbie with zero knowledge of code so any dumbed down responses are much appreciated, LOL. Your help along with others has been extremely helpful. 

Votes

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 ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

LATEST

Hi, what code did you use and where did you use it?

Votes

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