Skip to main content
Jymnazium
Participating Frequently
Aug 1, 2017 5:15 PM UTC
Answered

Displaying Field Based on Value Range

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

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Aug 1, 2017 6:45 PM UTC

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

7 replies

Inspiring
Aug 1, 2017 5:56 PM UTC

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.

Translate
Jymnazium
JymnaziumAuthor
Participating Frequently
Aug 1, 2017 6:30 PM UTC

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;

}

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

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Aug 1, 2017 6:45 PM UTC

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

Translate