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

Text box output not changing based on calculation in another box

New Here ,
Oct 15, 2024 Oct 15, 2024

Copy link to clipboard

Copied

Hi- I have zero JavaScript experience but I'm trying to learn.  I am creating a performance evaluation and would like the output of a text box to change based on the score.  I've found a few other scripts that seem to do the same, but when I try them (after I adjust my field names, scores, and output text), each of these scripts only displays whatever is in the boxes when the form is opened-- that is, the output does not change if the scores do.  So I have checkboxes that when checked make up the score, in a field called "Score".  I would like another box to put an output of either "does not meet standards" "good" "exceeds standards" (the output doesn't matter right now, I'm just trying to get the script correct before I build everything else).  I've tried these two, and again, they BOTH give the output correctly, but only the first time.  How do I get the output to change when the Score field changes?  Thank you.

 

var score = Number(this.getField("Score").valueAsString);

if (score<5) {event.value = "does not meet";} else if (score<=7.5) {event.value = "meets";}

else if (score<=10) {event.value = "Good"}

 

 

 

 

 

var calcVal = this.getField("Calc_Score").value;

if(calcVal == "")

   event.value = "";

if (Number(calcVal) == 16) {

    event.value = "PERFECT!!";

}else if (Number(calcVal) > 11) {

    event.value = "PASS";

} else {

    event.value = "FAIL";

}

TOPICS
Create PDFs , JavaScript , PDF , PDF forms

Views

80

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 ,
Oct 15, 2024 Oct 15, 2024

Copy link to clipboard

Copied

Use script in 'Calculate' tab as 'Custom calculation script' not in 'Format' tab.

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 ,
Oct 15, 2024 Oct 15, 2024

Copy link to clipboard

Copied

Also, you need to add "else" before this line:

if (Number(calcVal) == 16) {

Otherwise, the field will never be empty.

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 ,
Oct 15, 2024 Oct 15, 2024

Copy link to clipboard

Copied

LATEST

Thank you very much, I appreciate it.

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