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

Displaying Field Based on Value Range

Explorer ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

In my form, I'm trying to display a text box based on the value entered in another field (labeled Rating) falling into the range of 3.5 to 5.0. I've done a lot of research and everything I found says that the jscript code below should do what I want, but clearly I'm missing something as it has no effect. Note, I'm putting this as a custom calculation script in the box I want to show/hide.

---------------------------

if ((this.getField("Rating").value > "3.5") || (this.getField("Rating").value < "5")){

event.target.display = display.visible;

}

else{

event.target.display = display.hidden;

}

--------------------------

Anyone have any idea what I might be doing wrong?

Jim

TOPICS
Acrobat SDK and JavaScript , Windows

Views

661

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

correct answers 1 Correct answer

Community Expert , Aug 01, 2017 Aug 01, 2017

Your condition doesn't make sense... Any number is either bigger than 3.5 or smaller than 5. Maybe you mean bigger then 3.5 AND smaller then 5? If so, replace "||" with "&&" in your code (without the quotes).

Votes

Translate

Translate
LEGEND ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

Change that first line to the following:

if ((this.getField("Rating").value > 3.5) || (this.getField("Rating").value < 5)){

So that the comparison is using numerical values, not strings.

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
Explorer ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

Dangit, I posted the one with quotes...

My last try was as you suggested (below) and it also seems to do nothing.. I can set "Rating" field to 2, 3, 6, etc.. and the field always shows.

--------------------

if ((this.getField("Rating").value > 3.5) || (this.getField("Rating").value < 5)){

event.target.display = display.visible;

}

else{

event.target.display = display.hidden;

}

-------------------------------

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 ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

Your condition doesn't make sense... Any number is either bigger than 3.5 or smaller than 5. Maybe you mean bigger then 3.5 AND smaller then 5? If so, replace "||" with "&&" in your code (without the quotes).

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
Explorer ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

Thanks Try67! You were correct, using the "OR" logic instead of "AND" made it work perfectly....

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 ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

The other way around, you mean...

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
Explorer ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

Yes, correct.... I was going to edit and fix it.. but apparently I can't edit my own 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 ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

LATEST

You can change or delete a posting when there are no replies.

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