Skip to main content
Inspiring
October 13, 2023
Answered

JavaScript Needed - checkbox or button adds text to a field that can be edited

  • October 13, 2023
  • 3 replies
  • 457 views

Hello There...

I have a document that I added checkboxes to the team can select to add text to another field.  This is the javascript I used on the field the text is populating in:

 

if(this.getField("RP").valueAsString != "Off")
event.value = "SEE SERVICE WORK ORDER FOR JUSTIFICATION - Service and Repair To:";

else if(this.getField("M").valueAsString != "Off")
event.value = "[AGE] Year Old [SEX] with a history of [DX] requiring Modification to [EQUIPMENT] for mobility.";

else if(this.getField("NRB").valueAsString != "Off")
event.value = "[AGE] Year Old [SEX] with a history of [DX] requiring [EQUIPMENT] for mobility.";

else
event.value = "";

 

The problem is I need the team to be able to double click on the words with brackets around them to highlight and change them.  With this script, as soon as they change the words, the script reverts they sentence back.  Any ideas to make this work?

This topic has been closed for replies.
Correct answer Kevin From Chicago

I created Radio Buttons instead of checkboxes and added the following script:

if (event.target.value=="Choice1") this.getField("Justification").value = "SEE SERVICE WORK ORDER FOR JUSTIFICATION - Service and Repair To:";

3 replies

Kevin From ChicagoAuthorCorrect answer
Inspiring
October 13, 2023

I created Radio Buttons instead of checkboxes and added the following script:

if (event.target.value=="Choice1") this.getField("Justification").value = "SEE SERVICE WORK ORDER FOR JUSTIFICATION - Service and Repair To:";

MarkWalsh
Inspiring
October 13, 2023

You should really create separate entry fields for 'AGE', 'SEX', 'DX' and 'EQUIPMENT', and use those values in your calculation.

Nesa Nurani
Community Expert
Community Expert
October 13, 2023

You have a couple of options, remove 'else' part from your script, it will allow users to enter custom text.

Or use scripts in each checkbox.