Copy link to clipboard
Copied
Hi All,
I have the following JS doing a calculation for me
event.value = this.getField("Keel to Truck").value - ((this.getField("FWD DRAFT").value + this.getField("AFT DRAFT").value) / 2);
but would also like the option of overriding the calculated value with a manully inputed number. Is there an easy way to this??
Thanks
LC
Small correction: Use "Off", not "OFF".
Copy link to clipboard
Copied
There are several ways to override a calculation. How do you want this to work. Do you want the user to just type into the field? The easiest method is to use a checkbox to enable/disable the calculation.
Copy link to clipboard
Copied
Sorry about the delay in getting back to you. I like the idea of chackbox to enable / disable the calculation - is this easy to do??
Thanks
LC
Copy link to clipboard
Copied
Add this code to the bottom of the calculation script.
event.rc = this.getField("Checkbox").value == "Off";
event.target.readonly = event.rc;
When the checkbox is checked the field will block the calulation and allow user entry. When unchecked the calculation will proceed and the field will block user entry.
Copy link to clipboard
Copied
Thanks for the above. This is what I have done
event.value = (this.getField("KEEL TO TRUCK").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value))/2) event.rc = this.getField("AIR CALC").value == "OFF"; event.target.readonly = event.rc;
but its now not doing the calculation - I did also try the following
event.value = (this.getField("KEEL TO TRUCK").value) - ((this.getField("FWD DRAFT").value + (this.getField("AFT DRAFT").value))/2);
event.rc = this.getField("AIR CALC").value == "OFF";
event.target.readonly = event.rc;
but that didnt work for me either.
Copy link to clipboard
Copied
Now you need to do a bit of debug. First check the consol window to see if any errors are reported. Also, use the console window to ensure that this code
this.getField("AIR CALC").value == "OFF"
returns true when the checkbox is unchecked and false when checked.
It would also be helpful it you could post the form.
Copy link to clipboard
Copied
Small correction: Use "Off", not "OFF".
Copy link to clipboard
Copied
Thank you. it appears to be working as needed. Much appreaciated.
Copy link to clipboard
Copied
What should happen if they change the value of one of the other fields after entering a custom value?
Copy link to clipboard
Copied
It wont matter if they change the one of the other values - somtimes the real life scenario is not the same as the calculation for various reasons. so once a number is manully entered I am happy for it to stay that way. The form constantly gets duplicated and blank one filled in each time I use it.