Displaying Field Based on Value Range

Explorer ,
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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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).

TOPICS
Acrobat SDK and JavaScript, Windows

Views

232

Likes

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

Displaying Field Based on Value Range

Explorer ,
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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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).

TOPICS
Acrobat SDK and JavaScript, Windows

Views

233

Likes

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
Aug 01, 2017 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Aug 01, 2017 0
Explorer ,
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;

}

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

Likes

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
Reply
Loading...
Aug 01, 2017 0
Most Valuable Participant ,
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).

Likes

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
Reply
Loading...
Aug 01, 2017 0
Explorer ,
Aug 01, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 01, 2017 0
Most Valuable Participant ,
Aug 01, 2017

Copy link to clipboard

Copied

The other way around, you mean...

Likes

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
Reply
Loading...
Aug 01, 2017 1
Explorer ,
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...

Likes

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
Reply
Loading...
Aug 07, 2017 0
Adobe Community Professional ,
Aug 07, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 07, 2017 0