Copy link to clipboard
Copied
Hi
I’m completely new to the world of Javascript but muddling through putting together a pdf form. This forum has been a massive help and got me almost to the a finished form. I’ve hit a bit of a wall though and unable to find the solution so far. I hope someone can help.
The form has a dropdown field: Metre_Feet_display
with 2 options - Feet or Metres & commit selected value immediately is checked.
The form also has a number field: veRow1_3
I want to display either “ ft” or “ m” as a suffix to veRow1_3 based on the value of Metre_Feet_display
I have entered this code in the custom format script:
if (event.value) event.value = event.value +(this.getField("Metre_Feet_display").valueAsString);
This works when I enter a number in veRow1_3 and tab out of it. But If there's already a number entered, and I change Feet to Metres in the dropdown, it doesn’t update. I’ve tried variations of my code using .target.value but to no avail so far.
As an aside, I’m also using Metre_Feet_display value to determine a factor for use in a calculation that also uses the value of veRow1_3. This calculation doesn’t update either until I’ve updated/revised veRow1_3 value. I suspect if I can resolve the suffix issue, I can figure out the latter issue.
What am I doing wrong? TIA
Needed to declare variables as number and also there was delay in field calculation order. try now:
https://drive.google.com/uc?export=download&id=1rExcGToyeQNp-kBaA3cvU-HyBQU74kUO
Copy link to clipboard
Copied
You won't be able to do it just using format script,to live update changes you need calculation script.
Can you share file here so we can take a look?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Should field veRow1_3 be equal to Metre_Feet_display?
Copy link to clipboard
Copied
No - it's a data entry field but I want the suffix to be Metre_Feet_display.
Copy link to clipboard
Copied
See if this is anything close to what you looking for:
https://drive.google.com/uc?export=download&id=1qbzPYax3K6YHGhJzMuXRXyg8_38o7SFf
TIP: Since you used Math.log and Math.sqrt there is also Math.PI it returns Pi.
Copy link to clipboard
Copied
Oh Nesa Thank you. The suffix is perfect. I could never have managed the code you've added. The Temp calc uses the wirefactor (which is driven by the change in feet or metres). While I can see the factor change, it's not getting incorpoarted into the calc. I hope it's something simple.
Thansk again.
Copy link to clipboard
Copied
Where in calculation is problem, can you describe?
Copy link to clipboard
Copied
Sure. The mathematical calculation is fine. But it uses:
var Fact = this.getField("wirefactor").value;
wirefactor value is determined by the option selected in measure_scale dropdown.
So when it's set to metres, the value is 1, when feet, the value is 0.3048.
The value is setting correctly as I change the dropdown selection but it is not updating the calculated field in Wire GaugeRow1_2
Does this help clarify? I appreciate your help.
Copy link to clipboard
Copied
Where in calculation is "Fact" used?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thats not new file.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You removed some of my codes, see if it works now:
https://drive.google.com/uc?export=download&id=1yEwFQHEWYiSlR6cIp566qWQq7jRPqWOe
Copy link to clipboard
Copied
Hi Nesa
I really do appreciate your time. This is so strange. It's not working.
When set to metres, with 50a & a total of 10 between -ve & +ve (made up anyway you like), the answer should be 3.33.... It calculates correctly when set to metres, 50a, 0 in -ve & 10 in +ve. Any value in -ve and it doesn't calculate correctly.
With the same settings for feet - the answer should be 8.45. Again, where the +ve is 10 but -ve 0, the answer is correct. Any value in -ve and it doesn't calculate correctly.
And when I change the dropdown, even when only the +ve value entered, it doesn't recalculate for me. I have to delete the contents first. Sorry to be a pain.
Copy link to clipboard
Copied
Needed to declare variables as number and also there was delay in field calculation order. try now:
https://drive.google.com/uc?export=download&id=1rExcGToyeQNp-kBaA3cvU-HyBQU74kUO
Copy link to clipboard
Copied
Brilliant! Thank you so much!