I recommend you do the percentage value in a separate field. It will make things easier.
You could then combine both tasks into a single calculation script, like this:
var grandTotal = Number(this.getField("GrandTotal").value); var gtPerc = grandTotal / 150; if (gtPerc<0.5) this.getField("OverallRating").value = "1"; else if (gtPerc<=0.7) this.getField("OverallRating").value = "2"; else this.getField("OverallRating").value = "3"; event.value = "(" + (gtPerc*100).toFixed(2) + "%)";
Replace the field-names and check-box export values with the actual ones in your form, of course.
Edit: Fixed the last line of the code to match your desired format.
Thank you try67 for your quick response.
I will do the percentage in a separate field beside the Grand Total field.
But as I know little about scripting and related matters I have to ask where this script goes. I take it that the 'OverallRating' gets changed to the three radio button choices (Below Standard, Standard and Superior as I have labeled those three buttons that way? Like this?
- var grandTotal = Number(this.getField("GrandTotal").value);
- var gtPerc = grandTotal / 150;
- if (gtPerc<0.5) this.getField("Below Standard").value = "1";
- else if (gtPerc<=0.7) this.getField("Standard").value = "2";
- else this.getField("Superior").value = "3";
- event.value = "(" + (gtPerc*100).toFixed(2) + "%)";
Not sure what you mean by 'check-box export values' or where to put this script to have the radio buttons automatically selected based on the percentage calculated.
This script should be placed as the custom calculation script of the percentage field.
Instead of creating three separate fields I recommend you name them all the same (I used "OverallRating" in my code, but it could be something else), and give each one a unique value (it could be "1", "2", "3", like in my code, or it could be "Below Standard", "Standard" and "Superior"). The fields can be either check-boxes or radio-buttons, it doesn't matter.
Thanks sooo much. Was able to to get it to work. I created the separate field, labeled it 'Percentage', added the script in the 'custom script' box on the 'Calculate' tab. Tweaked the Radio Button's name to 'OverallRating' and set each button's choice to separately to 1, 2 or 3, made sure the script reflected those names and values. When I entered the values in the various fields the script ran and chose the appropriate radio button based on the total but no value was put in the 'Percentage' field and after enter values in the various fields I kept getting this response:
I did figure out that the format for the 'Percentage' field was to be left at 'none' instead of 'percentage'. Probably the fact that I don't completely understand scripting.
May I ask one more question. In the other fields (that get added up) the person is suppose to enter a value from 1 to 5 or 1 to 10. Is there a way to limit/restrict someone entering a number outside of that range?
Many thanks for all your help.
Sure, it's easily done. Set their Format option to Number and then you'll be able to set a valid range under the Validation tab.
Got it. Thanks again try67.