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

Can I make JavaScript text boxes editable

New Here ,
Apr 15, 2020 Apr 15, 2020

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?

TOPICS
PDF forms
2.3K
Translate
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
LEGEND ,
Apr 15, 2020 Apr 15, 2020

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?

Translate
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
New Here ,
Apr 15, 2020 Apr 15, 2020

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

Translate
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 ,
Apr 15, 2020 Apr 15, 2020

At the calculation you can at the end something like this:

event.value = event.value + " your text ";

Translate
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
New Here ,
Apr 15, 2020 Apr 15, 2020

Would this allow for any text or would I have to specify what my text is?

Translate
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 ,
Apr 15, 2020 Apr 15, 2020

You can use any text.

Translate
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 ,
Apr 15, 2020 Apr 15, 2020

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.

Translate
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
New Here ,
Apr 15, 2020 Apr 15, 2020

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 

Translate
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 ,
Apr 15, 2020 Apr 15, 2020

You can generate a random 4-digit number with a script and apply it to your field.

Translate
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
New Here ,
Apr 15, 2020 Apr 15, 2020

It has to be generated by a piece of software we use unfortunately 

Translate
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 ,
Apr 15, 2020 Apr 15, 2020

So you want to allow the users to enter this "random" four-digit number, then?

Translate
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
New Here ,
Apr 15, 2020 Apr 15, 2020

Yes that's correct

Translate
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
New Here ,
Apr 15, 2020 Apr 15, 2020

In case anyone does stumble on this I did end of fixing the issue:

// Allow user data input
if (event.source!=event.target) {
event.value = this.getField("Variable 1").value + "" + this.getField("Variable 2").value + "" + this.getField("Variable 3").value;
Translate
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 ,
Apr 16, 2020 Apr 16, 2020

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. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Apr 16, 2020 Apr 16, 2020

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. 

Translate
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 ,
Apr 16, 2020 Apr 16, 2020
LATEST

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. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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