Skip to main content
Inspiring
November 13, 2023
Answered

Adobe Form Code no longer works when I change a field name in code

  • November 13, 2023
  • 2 replies
  • 1425 views

I have created a large code (thanks to help from people on this forum) and it has worked perfectly for what I have needed but I am having some trouble with it right now.

 

When I change a field name within the code, it usually isn't a problem until now. I have changed 'Vantagequote' to 'Vantageinstallationprice' (B.value) and suddenly the whole code no longer works...as in it stops populating all the other fields. If I change 'Logic' or any of the other field name, it does not affect the code's function, even with or without a field of the same name within the text. When I change the Vantage field name, if the name does NOT match the target field name, then the code WORKS. When the field name in the code is EXACTLY the same name as the target field name, the whole code stops working. 

The code was a copy from another document (copied the dropdown field over to the new document without issue) but I have made changes to it now, which has worked until now., including changing field names and data in the code. I did try to put a field in with the original name to try and make it work but the same problem happened. It is only happening with 'Vantage...'

 

I have also tried deleting and replacing the target field but it didn't work. I have no clue as to what is going on. 

 

Here is a part of the code so that you get the idea of what it is. The code is in order of calcuation on the form and I want to keep this code's structure for I will be teaching a non-technical person how to change prices in it when needed. I have found that this works well for others to read and understand. 

 

Any help would be greatly appreciated.

 

var S = this.getField("Digtype");
var L = this.getField("Minidigperday");
var E = this.getField("Miniminidigperday");
var V = this.getField("Logic");
var B = this.getField("Vantageinstallationprice");
var A = this.getField("Beamsizetotal");
var C = this.getField("PoolSize1");
var D = this.getField("Tons");
var F = this.getField("Standardmachineprice");

 

if(event.value == "Compass Plunge 2.8m x 2.13m"){
S.value = "Standard 3-ton Machine";
F.value = 1800;
L.value = 1;
E.value = 1;
V.value = 1500;
B.value = 2800;
C.value = "2.8m x 2.13m";
D.value = 50;
A.value = 2450;}

 

else if(event.value == "Compass Plunge 3.8m x 2.13m"){
S.value = "Standard 3-ton Machine";
F.value = 1800;
L.value = 1;
E.value = 1;
V.value = 1500;
B.value = 2800;
C.value = "3.8m x 2.13m";
D.value = 50;
A.value = 2450;}

 

//etc.

This topic has been closed for replies.
Correct answer Tanya32803897q3c4

Hi Nasa,

Happy to share it with you. I actually got the simple code off you for another form and built from there. It is a very big code but it works for my purposes. I have learned how to write it another way to be more efficient but this works for what my boss wants. I have had no trouble like this before.

Is there a way to share it with you that is not this public? I don't know if my boss would approve of it in a public view. Happy to email it do follow instructions to send it to you another way. 

 

The code is in validation of Pooltype1. 


Thank you Nesa. 

I had a word missing throughout my code that I had not seen. 

2 replies

Bernd Alheit
Community Expert
Community Expert
November 13, 2023

Where does you use the script?

Inspiring
November 13, 2023

I should clarify. I had some amazing help from people who have given me a simplified version of this code and it was great to build off. I just don't know what is happening here. 

 

Thom Parker
Community Expert
Community Expert
November 13, 2023

It is very important that the field names in the code exactly match the field names on the form. 

However, it's is easy to miss small things. 

Look in the console window (press Ctrl-j) to see if an error is reported.  

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
November 13, 2023

Hi Thom,

I made sure the field names were exact. I had that issue before with extra spaces or incorrect names. I can easily work those out. This time no matter what I do, this one field name change will not work with the target field box, regardless of the name I set up in the target field and put into the code. 

I have also checked to see if the target field is the same format as what is in the code (number), which it is.  

I wondered how to check the console. Thank you. I just checked it but there are no errors that came up in the console. I enabled the debugger and had it validate my script but there was nothing on the console to suggest that there was anything wrong.

 

Interesting thing tho, when the field name is different from the target field, the form populates quickly. But the moment I have the correct name, the form slows down, almost freezes for a couple of seconds and then unfreezes without populating. 

Last time I had an issue of no population of fields, I had to change the order of calculations within the code. I did that and still having the same issue.