Skip to main content
PaulusMaximus
Known Participant
September 30, 2024
Answered

Set the default field to the value of a previous variable

  • September 30, 2024
  • 1 reply
  • 1076 views

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.

This topic has been closed for replies.
Correct answer try67

As 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?!)


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

 

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

1 reply

PDF Automation Station
Community Expert
Community Expert
September 30, 2024

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?

PaulusMaximus
Known Participant
September 30, 2024

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 30, 2024

As 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?!)


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

 

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