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

JavaScript help - calculated number would receive label in another field

New Here ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

Hello,

 

I am extremely new to PDF creation and I'm hoping to get some help. I'm creating a PDF of a rating scale where a subject is rated on different tasks in different domains. So far I have it figured out that once the rating scale number is input, it will calculate the raw domain score and the average domain score. 

 

The part I'm stuck on is I'm trying to add a label then based on the average domain score. Below is the scale with labels, so for example if the calculated value is 1.33 I'd like the field to automatically put the label "Mild".

 

0.0-0.49 None

0.50-1.49 Mild

1.50-2.49 Moderate

2.50-3.49 Severe

3.50-4.0 Extreme

 

Is this something that can be accomplished in JavaScript? Any help would be greatly appreciated! Thank you for your time.

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF

Views

82

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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

You can use this code as the custom Calculation script of the label text field:

 

var averageDomainScore = Number(this.getField("average domain score").valueAsString);
if (averageDomainScore<0.5) event.value = "None";
else if (averageDomainScore<1.5) event.value = "Mild";
else if (averageDomainScore<2.5) event.value = "Moderate";
else if (averageDomainScore<3.5) event.value = "Severe";
else if (averageDomainScore<=4) event.value = "Extreme";
else event.value = "";

View solution in original post

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 ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

You can use this code as the custom Calculation script of the label text field:

 

var averageDomainScore = Number(this.getField("average domain score").valueAsString);
if (averageDomainScore<0.5) event.value = "None";
else if (averageDomainScore<1.5) event.value = "Mild";
else if (averageDomainScore<2.5) event.value = "Moderate";
else if (averageDomainScore<3.5) event.value = "Severe";
else if (averageDomainScore<=4) event.value = "Extreme";
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
New Here ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much! That worked perfectly and did everything I wanted it to do.

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