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

Add text dependant on radio button

Contributor ,
Oct 20, 2024 Oct 20, 2024

I have 3 radio buttons under the heading of 'Group3', the individual buttons have the export values of self, 60 and 150

 

I have 3 text fields selfA, 60A and 150A and what I want to happen is if someone selects the self option, the letter X appears in selfA, if they select 60, the letter Y appears in 60A and if they select 150, the letter Z appears in 150A

 

I can get this to 'sort of' work by using the following in the mouse up action of the radio box:

 

var cText = "Z";

this.getField("150A").value = (event.target.value == "Off")? "" : cText;

 

but it's obviously not right because while the letters do appear in the relevant fields, if the radio box selection is changed, the letters don't diappear from the other fields. I need to be left with the relevant letter that corrsponds to the box checked only, the other 2 text fields need to be empty.

TOPICS
JavaScript , PDF , PDF forms
425
Translate
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
LEGEND ,
Oct 20, 2024 Oct 20, 2024

++EDITED REPLY

 

Hi there @jlehane ,

 

Although my preferred method would've been to employ a single script in one of the textfields as a Custom Calculation Script, I would stick to answering your original inquiry by employing a script for each of the radio buttons in use.

 

For the scripts (which are illustrated below) to work properly, you must assign an different export value to each of the grouped radio buttons under the heading of 'Group3' (i.e first radio button assign export value of "X", second radio button "Y", and third radio button "Z" respectively). 

 

So, with no further delays, very quick and easy, just copy the script below and paste it in the first radio button Mouse Up event script editor:

 

 

var f = event.target;

if(f.isBoxChecked(0)){

this.getField("selfA").value = f.value;
this.getField("60A").value   = "";
this.getField("150A").value  = "";

}

 

 

Use this script for the second radio button:

 

var f = event.target;

if(f.isBoxChecked(1)){

this.getField("selfA").value = "";
this.getField("60A").value   = f.value;
this.getField("150A").value  = "";

}

 

 

And use this one for the third radio button:

 

var f = event.target;

if(f.isBoxChecked(2)){

this.getField("selfA").value = "";
this.getField("60A").value   = "";
this.getField("150A").value  = f.value;

}

 

 

NOTES:

In the example scripts above, I employing the isBoxChecked() function method to test for the 'checked' status property of the radio button widget that a user will be clicking on. 

 

Rather than using a conditional expression to check for the "Off" export value (when a checkbox is unchecked), this method returns a value of zero(0) if the radio button is unchecked, and a value of one(1) if it is checked. Manually assigning a desired export value to each radio button is used instead to display that value automatically in the desired textfields (eliminating the excessive use of variable declarations).

 

Note that, you have three radio buttons grouped together under the 'Group3' heading. In other words, f.isBoxChecked(0)  represents the first radio button under the 'Group3 heading, f.isBoxChecked(1)  represents the second radio button, and f.isBoxChecked(2) the third radio button respectively. Therefore, the declared varibale "f" in the expression, it tells the script in which target field  the 'checked' event will execute from.

 

I hope that this clarifies a few things.

 

Additional Suggestion:

 

You may want to consider employing an Action Button to reset the checked status of the radio buttons and to clear the textfields (if desired).

 

Otherwise, radio buttons widgets are designed to work in groups, and once the user clicks on any of those radio buttons to make a selection, that last selection will always stays active. In which case, employing checkboxes may be more desireable.

 

Translate
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
Contributor ,
Oct 21, 2024 Oct 21, 2024

Thank you @ls_rbls . I would have used checkboxes, but there was a reason I couldn't, but I can't remember what that reason was!! 🤦🏻‍♀️The document was originally created a few years ago and I 'think' it was something to do with these radio boxes needing to be visible after the document has been sent through Adobe Sign for the end customer to make the selection. And with checkboxes, this wasn't possible. Not sure.......

Translate
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
LEGEND ,
Oct 21, 2024 Oct 21, 2024
LATEST

You're very welcome.

Translate
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 ,
Oct 20, 2024 Oct 20, 2024

Do you want the user to be able to override these texts in the text fields, or should they be determined solely based on the selection in the radio-button group?

Translate
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
Contributor ,
Oct 21, 2024 Oct 21, 2024

No, these texts won't even be visible to the user and they are solely based in the radio button selected.

For a bit more context, the letter we're left with, will be merged into another cell which in turn will pull a specific sentence into another field!

Translate
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