Skip to main content
rockinrob
Known Participant
July 30, 2024
Answered

Want my radio button choice to control which text field shows

  • July 30, 2024
  • 2 replies
  • 2152 views

I am a newbie trying to do something similar to "Hide text field on radio button for JSNewbie." (matth92962896 New Here, Jun 06, 2018) - but I can't make it work. 

 

I want my radio button choice to control which text field shows. 

My radio button group is "payment-PWB" choices are "Choice1-PWB" "Choice2-PWB" "Choice3-PWB" 

Coordinating text fields are "check for-PWB" "CC for-PWB" "wire transfer-PWB"

 

I tried creating a hidden text field and set this code as its custom calculation script:

 

var v = this.getField("payment-PWB").valueAsString;

this.getField("Choice1-PWB").display = (v=="check for-PWB") ? display.visible : display.hidden;

this.getField("Choice2-PWB").display = (v=="CC for-PWB") ? display.visible : display.hidden;

this.getField("Choice3-PWB").display = (v=="wire transfer-PWB") ? display.visible : display.hidden; 

 

but it's not working. Can anyone see what I am doing wrong? I would greatly appreciate any advice!

thank you

 

This topic has been closed for replies.
Correct answer PDF Automation Station

I now have my text fields totaling. I also want the total text fields to show/hide according to the payment choice check marks. I now have these scripts as actions for the three checkmarks and they turns the total "on," it just doesn't turn it "off" when a different payment option is checked.  nope, I just double checked the check marks are doing nothing. I'll try the console

 

this.getField("checkmoneyorder_total").display = (event.target.value === "Off") ? display.hidden : display.visible;

this.getField("creditcard_total").display = (event.target.value === "Off") ? display.hidden : display.visible;

this.getField("wiretransfer_total").display = (event.target.value === "Off") ? display.hidden : display.visible;

 

I am such a novice I should have apologized in advance. I really need to take a beginner class instead of muddling through.


Enter the following script as a mouse up action in all three radio buttons:

var choice=event.target.value;
this.getField("check for-PWB").display=display.hidden;
this.getField("CC for-PWB").display=display.hidden;
this.getField("wire transfer-PWB").display=display.hidden;
if(choice=="Choice1-PWB")
{this.getField("check for-PWB").display=display.visible;}
if(choice=="Choice2-PWB")
{this.getField("CC for-PWB").display=display.visible;}
if(choice=="Choice3-PWB")
{this.getField("wire transfer-PWB").display=display.visible;}

I developed a (paid) course for beginners that you can take a look at here.

2 replies

Bernd Alheit
Community Expert
Community Expert
July 31, 2024

Look at the JavaScript console for errors (ctrl-j).

PDF Automation Station
Community Expert
Community Expert
July 30, 2024

You are calling choices (export values) as field names.  Change your choices to match the text field names then enter the following custom calculation script in each text field:

event.target.display=(this.getField("payment-PWB").value==event.target.name)?display.visible:display.hidden;
rockinrob
rockinrobAuthor
Known Participant
July 30, 2024

thank you PDF Automation Station! I've tried this:

 

event.target.display=(this.getField("payment-PWB").value==PWB_programsprices)?display.visible:display.hidden;

 

where "payment-PWB" is the radio button check box payment options and "PWB_programsprices" is the 18 radio buttons named with $$ values. I seem to be missing the piece to get the value to show at all in the boxes at bottom right.

 

thank you so much for responding!

PDF Automation Station
Community Expert
Community Expert
July 30, 2024

Your question was about showing and hiding fields, not about showing values.  Please explain exactly what you want this form to do.