
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 06:50 PM
I have a field (FieldD) that is set based on other fields on a form. i.e. their onChange event runs a script that updates the value in FieldD.
FieldA (onChange recalculates value in FieldD)
FieldB (onChange recalculates value in FieldD)
FieldC (onChange recalculates value in FieldD)
FieldD
I now want to also add an onChange event for FieldD that will process things if the user overrides the automatic value by typing something in there directly. The problem is, FieldD's onChange event will fire when the field is changed by the user directly, OR, when onChange events of FieldA, FieldB, or FieldC fire.
Does anyone know of a way to add to FieldD's onChange code to say "Only fire if the change is happening directly in FieldD"?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 07:15 PM
I have done this before by using variable to specify when to ignore FieldD's onchange function.
Create an onLoad Client Script that declares a variable like: var isAutoRecalculating = false; (or something)
In your FieldA-C onChange functions, set isAutoRecalculating to true, then run the recalculation, set the new value of FieldD (this in when the FieldD onChange gets called), then AFTER you set the new value of FieldD, set isAutoRecalculating back to false.
In your FieldD onChange function have a line at the top that says:
if (isAutoRecalculating)
return;
// Do normal stuff here if not autoRecalculating

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 07:15 PM
I have done this before by using variable to specify when to ignore FieldD's onchange function.
Create an onLoad Client Script that declares a variable like: var isAutoRecalculating = false; (or something)
In your FieldA-C onChange functions, set isAutoRecalculating to true, then run the recalculation, set the new value of FieldD (this in when the FieldD onChange gets called), then AFTER you set the new value of FieldD, set isAutoRecalculating back to false.
In your FieldD onChange function have a line at the top that says:
if (isAutoRecalculating)
return;
// Do normal stuff here if not autoRecalculating

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 08:10 PM
Perfect! Thanks - didn't think of that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 02:21 PM
If you are still around, I have similar issue, a single multi-line field, server name per line (users sometimes supply commas at end and I have to reject that)
This code runs fine first time but because line 8 modifies the newvalue, it runs again and because my code adds commas (designed this way) it then barks thinking the user supplied commas.
How do I stop it from running a second time?
The first if is supposed to prevent this but it fails to.