• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Updating a variable suffix

Community Beginner ,
Mar 24, 2021 Mar 24, 2021

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

TOPICS
PDF forms

Views

14.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 24, 2021 Mar 24, 2021

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 

Votes

Translate

Translate
Enthusiast ,
Mar 24, 2021 Mar 24, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Thank you!

I've attached the file here (or a subset of it).

The Temp Calc field (pg2) should also pick up the change in the dropdown value so Isuspect it's the same error on both. Any insight is much appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Should field veRow1_3 be equal to Metre_Feet_display?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

No - it's a data entry field but I want the suffix to be Metre_Feet_display.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2021 Mar 24, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Where in calculation is problem, can you describe?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Where in calculation is "Fact" used?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Yeah - good spot. I had hoped this cracked it but it's still not right. In fact, now it gives different answers (sometimes NaN), for the same entries. I think there must be something wrong in my code. I've attached the correct file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Thats not new file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Sorry!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2021 Mar 24, 2021

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2021 Mar 24, 2021

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

LATEST

Brilliant! Thank you so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines