Copy link to clipboard
Copied
I have JavaScript in many text boxes which auto populate, however, I also want to be able to add custom text in addition. Can I do this?
Copy link to clipboard
Copied
How would you see this working (for the user, not technically)? These fields auto-fill. The user changes it. Then what happens if, for example, the user changes one of the things which previously caused it to auto-fill?
Copy link to clipboard
Copied
So, at the moment I have JavaScript running in the calculated fields and it auto populates depending on what is selected in other fields which is working great. I've ran into the problem now that certain text boxes require manual text in addition to the auto populated text. Is there any way to code this into the java script? In reality I can't really think of a way this would work but I'm pretty new to coding so thought I'd ask to see if there was a way around this.
In short, I would still like the auto populate text to remain unchanged but I want to add in additional text. I am also the only user of this form so this doesn't apply to anyone else
Copy link to clipboard
Copied
At the calculation you can at the end something like this:
event.value = event.value + " your text ";
Copy link to clipboard
Copied
Would this allow for any text or would I have to specify what my text is?
Copy link to clipboard
Copied
You can use any text.
Copy link to clipboard
Copied
One of the ways of doing it is to only update the field if one of the fields it depends on for the calculation is updated.
For example, if field C and A+B then you only apply the calculation when either A or B are updated, not D, or C itself.
That allows the user to overwrite the automatic value, while not overwriting their value if a non-related field is change.
However, this can become quite complicated quite fast if the fields it relies on also have a calculated value, as you then need to maintain a list of all of the fields the should trigger the automatic calculation.
In short, it's not a simple or trivial coding task.
Copy link to clipboard
Copied
Would this also work if a field does have a value which is coded to auto populate a text field. Ideally I'd like this to still auto populate but be editable as well. The problem I have run into is that our forms all have a unique reference code and this code is dependent on factors in the form which I have put the 'rules' into java script so it just auto populates itself (which is working great), however, we also put in a randomly generated 4 digit code at the end but the text box can't be edited to add in this code now. I could just add another text box but I'd ideally like to make it a bit neater
Copy link to clipboard
Copied
You can generate a random 4-digit number with a script and apply it to your field.
Copy link to clipboard
Copied
It has to be generated by a piece of software we use unfortunately
Copy link to clipboard
Copied
So you want to allow the users to enter this "random" four-digit number, then?
Copy link to clipboard
Copied
Yes that's correct
Copy link to clipboard
Copied
In case anyone does stumble on this I did end of fixing the issue:
Copy link to clipboard
Copied
This solution will not work. If any other field on the form is changed, the entered text will be lost. These two things, calculated text and user entered text, are mutually exclusive. In order to get the behavior you want, the entered text would need to be stored, actually managed separtely, so that it could be restored when the field is again recalculated.
The solution is to have a separate field for the entered text.
Copy link to clipboard
Copied
If you clink on the link it also has a JavaScript to stop this disappearing depending on what text box is changed. It's worked for what I need it for.
Copy link to clipboard
Copied
It is an entirely inappropiate solution. To solve this type of issue you need to define specific triggers, or situations, there the field is either calucaleted or not calculated. Then use the correct overide properties.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more