4 Replies Latest reply on Jan 18, 2013 2:49 PM by demon_candy

# Custom Script for Generating a Number in a Range based on a Sum

Hello again,

I have a question regarding another custom script I am trying to create.

I currently have a simple script running in one field (Field A) that creates a sum based on the numbers entered in 7 boxes (Fields R1-R7), and a field (Field B) that creates an average based on the numbers entered in the 7 boxes.

What I would like to do, is to have Field B instead generate a number based upon what range the sum in Field A adds up to.

For example:

A total of 7-12 in Field 1 would generate a 1 in Field 2.

A total of 13-17 in Field 1 would generate a 2 in Field 2.

A total of 18-23 in Field 1 would generate a 3 in Field 2.

And etc.

I'm not sure if a custom script is even necessary - but I am kind of at a mental block with this one.

Any help would be greatly appreciated, thanks so much!

• ###### 1. Re: Custom Script for Generating a Number in a Range based on a Sum

You can use something like this as the custom calculation script of Field 2:

if (this.getField("Field 1").valueAsString=="") event.value  = "";

else {

var v1 = +this.getField("Field 1").valueAsString;

if (v1>=7 && v1<=12) event.value = 1;

else if (v1>=13 && v1<=17) event.value = 2;

else if (v1>=18 && v1<=23) event.value = 3;

}

• ###### 2. Re: Custom Script for Generating a Number in a Range based on a Sum

All I can say is wow - you are really awesome!!

This works perfectly, and I think I am starting to get the hang of Javascript a bit more.

You have been a really great help, thank you so much! ^_^

• ###### 3. Re: Custom Script for Generating a Number in a Range based on a Sum

You're welcome... but in the future, you should mark the reply with the answer as the correct one, not your own... :-)