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

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

Explorer ,
Oct 13, 2023 Oct 13, 2023

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?

TOPICS
Edit and convert PDFs , JavaScript , PDF
348
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
1 ACCEPTED SOLUTION
Explorer ,
Oct 13, 2023 Oct 13, 2023
LATEST

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

View solution in original post

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 13, 2023 Oct 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.

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
Advocate ,
Oct 13, 2023 Oct 13, 2023

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

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
Explorer ,
Oct 13, 2023 Oct 13, 2023
LATEST

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

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