- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 04:44 AM
Hi,
I am trying to create a script where the field displays the maximum value of 2 fields. So for example in Excel we would put in something like =MAX(D3:E3).
So in the below example Impact (Monetary) and Impact (Reputation) are both drop downs with a value of 1 - 5.
Impact max should display the maximum value (in the below case 5)
Any help would be much appreciated.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 05:11 AM
Hi Riaz,
Change the type onChange and select the field name as impact(reputation). Now paste the script as.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var a = g_form.getValue('u_impact_monetary');
var b = g_form.getValue('u_impact_reputation');
var c = Math.max(a, b);
g_form.setValue('u_impact_max',c);
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 05:05 AM
Hi Pradeep,
Thank you, I am really not a "scripter" so you may have to tell me in a little detailed way.
So i added the below client script o the form:
var a = g_form.getValue('current.u_impact_monetary');
var b = g_form.getValue('current.u_impact_reputation');
var c = Math.max(a, b);
g_form.setValue('current.u_impact_max',c);
What else do I need to change exactly? (Sorry but my scripting knowledge is not good at all I am a non technical person).
Thank you both for the very fast reply it is much appreciated.
Riaz

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 05:11 AM
Hi Riaz,
Change the type onChange and select the field name as impact(reputation). Now paste the script as.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var a = g_form.getValue('u_impact_monetary');
var b = g_form.getValue('u_impact_reputation');
var c = Math.max(a, b);
g_form.setValue('u_impact_max',c);
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 05:42 AM
Thank you both,
Almost I have been testing this and it certainty works.
The only thing is is that in order to get the max value in the Impact Max field a change has to be made to the Impact Reputation.
So for example if Impact Monetary can be set to 3 and Impact Reputation 4 that will = Impact Max to 4.
However if I change Impact Monetary to 5 now it will not change the Max value until Impact reputation is changed.
Any way of doing this so it recognises if either one is changed it picks the max value?
Many Many Thanks
Riaz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 05:44 AM
I think I would just duplicate the onChange script to watch both fields for changes and update the Max field when either one changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 05:48 AM
Thank you Both this works Perfectly
Fantastic... Thanks Pradeep and Kenneth very much appreciated
Riaz