These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

returning string based on value

krharlan
Registered: Aug 4 2009
Posts: 3

I have a form calculating values depending on which box checked - i.e. box 1 = 3 points, box 2 = 5 points, etc...

What I am looking is a way to return a string value based on a total score - like

1 - 100 returns loser
101 - 300 - needs help
301 - 500 getting there
501 - 600 pro...etc.

Can anyone suggest any code?

My Product Information:
Acrobat Pro 8.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You can use one of JavaScript's conditional statement.

Using the 'if' statement with the tests in ascending order:
// code to sum the check boxes into a variable called fScore goes here// test the value of fScorevar sRating; //default resultif(fScore < 101) {sRating = 'loser';}if(fScore < 301) {sRating = 'needs help';}if (fScore < 501) {sRating = 'getting there';}if (fScore < 601) (sRating = 'professional'}// all other results 'outstandingif (sRating = '') {sRating = 'outstanding'}

Or one could use the 'switch' statement
// code to sum check boxes into variable fScore goes herevar sRating ;switch (true) {case (fScore > 0 & fScore < 101) :sRating = 'loser';break;case (fScore < 101) :sRating = 'loser';break;case (fScore < 301) :sRating = 'needs help';break;case (fScore < 501) :sRating = 'getting there';break;case (fScore < 601) :sRating = 'professional';break;default:// all other resultssRating = 'outstanding';break;}

George Kaiser

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Quote:
I must be missing someting - the actual code is below. I have it in a text field named
sRating - another text field named fScore calculates the totals.
The comment

Quote:
// code to sum check boxes into variable fScore goes here
Needs to be replaced or the code for obtaining the total to be added to the posted code.

So with a field named 'fScore' one can add the following code:
// get the sum of the scores from the 'fscore' fieldvar fScore = this.getField('fScore').value;

After setting the rating variable, one will also need to set the field's value:
event.value = sRating;
You also might want to add some code to prevent 'loser' when there is no check boxes selected.

George Kaiser