Skip to main content
Participant
May 3, 2018
Answered

How do I populate numeric value ranges in different fields on a two-page form?

  • May 3, 2018
  • 1 reply
  • 3029 views

I have a form that contains 6 different fields. I would like them to show values within ranges of a given answer. The field ranges are 5-8, 9-13, 14-17, 18-21, 22-25, and 26-30.

If the value falls between any given range, I would like for my form to populate the number in that range. The other fields should remain blank with no data showing unless the value moves to one of the other ranges. If it does, then the original field should blank out.

Example: for the field of 5-8: if I have a value of 6, then 6 should populate in the 5-8 text box. If the value changes to 12, the 5-8 text box should return to blank, and the 9-13 text box should show the value of 12.

As the values change, the other field range text boxes should react accordingly.

Here's my main problem- I can get the values to populate with the data using if and else if, but for some reason the blocks don't return to blank. They basically show residue numbers in the fields that the user would have to go and manually clear out. My scripting looks like this:

For the 5-8 field:

var v1 = this.getField("C/C Total Score").value;

if (v1 <= 0) {

event.value = " ";}

else if (v1 >=5 && v1 <=8) {

event.value = (v1); }

else if (v1 >8) { event.value = " ";}

For the 9-13 field:

var v1 = this.get.Field("C/C Total Score").value;

if (v1 >= 9 && v1 <= 13) {

event.value = (v1);}

else if (v1 >=13 &&v1 <=9) {event.value = " "; }

else if (v1 >13) {event.value = " "; }

The other range fields look similar except for number changes in the script.

Is there anyone that can help me achieve what I need to do?

This topic has been closed for replies.
Correct answer try67

You have overlapping conditions. For example, in the second script if the value is 9 it falls in both the first and second if-conditions. That's not good.

And you have a syntax error there, as well. You wrote "get.Field" instead of "getField". That should display an error message in the JS Console.

Also, your code is unnecessarily cumbersome. It could be optimized to just this:

var v1 = Number(this.getField("C/C Total Score").valueAsString);

if (v1 >= 9 && v1 <= 13) event.value = v1;

else event.value = " ";

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 3, 2018

You have overlapping conditions. For example, in the second script if the value is 9 it falls in both the first and second if-conditions. That's not good.

And you have a syntax error there, as well. You wrote "get.Field" instead of "getField". That should display an error message in the JS Console.

Also, your code is unnecessarily cumbersome. It could be optimized to just this:

var v1 = Number(this.getField("C/C Total Score").valueAsString);

if (v1 >= 9 && v1 <= 13) event.value = v1;

else event.value = " ";

lambo889Author
Participant
May 4, 2018

I will give this a shot tomorrow and see if it works. Hopefully it does and I'll be able to apply it to the other fields. I appreciate the quick response!