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

Set the default field to the value of a previous variable

Explorer ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

Hi there,

Is it possible to use a variable from a previous form as the default value (only) in another form?

For example, a previous form has the name 'totalhours' and calculates a total value of 6.25.

In my next form I would like to reference that value as the default value in a new text field, but allow the user to enter a new value independent of the previous variable 'totalhours'.

I see other posts where it is possible to set the defaultvalue, but I am unable to work out the javascript to my particular circumstance. In other words, I would like the default value for my new field 'desiredhours' to be generated from 'totalhours' merely as a default value.
If that's not clear enough, let me add that if I enter a new value in 'desiredhours' it will be a new value and not affect the original 'totalhours' it merely uses the value as a display start point.

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

90

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 ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

When you say "default value" do you mean initial value that can be overwritten, or do you mean default value that it will return to when the field is reset?  Do you want these forms connected so that 6.25 (in this example) is automatically used as the default value, or are you wanting to manually set it in form #2?

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
Explorer ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

Yes, I mean the default value that can be overwritten. I do NOT want the forms connected (such as totalhours#1)
I would like the new form to set a unique new field value, but use the calculation from the previous form as a starting point.

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
Explorer ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

form-idea-01.jpgAs an aside - it would be great if I could simply reference a field name in the 'default value' dialog box of options. (With no javascript required)
For example, I can manually enter any number or text as a 'default value' but if I could enter a variable reference such as #totalhours or $totalhours in this box, that would be superb. (I'm assuming that's not a thing?!)

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 ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

No, but you can do it using a simple calculation script:

 

if (event.value=="") event.value = this.getField("totalhours").value;

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
Explorer ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

Fantastic! It displays the right value, but for some reason, it works differently from a 'default value' because the other fields that use this field for calculation still assume a value of nil? (Until I type something in)
Is there a way to access/apply the same 'default value' variable?

 

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 ,
Sep 30, 2024 Sep 30, 2024

Copy link to clipboard

Copied

LATEST

Check your calculation order.

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