Copy link to clipboard
Copied
I need the textbox to pull values from 3 different textboxes... [<City>, <State> <Zip>] ... but if City or Zip code is empty (the State is never empty as the default value for the textbox is "CA"), then it should not hide the combined textbox...
First attempt:
//event.value = this.getField("Case City").valueAsString + "," + " " //+ this.getField("Case State").valueAsString + " " //+ this.getField("Case Zip Code").valueAsString;
This pulls the values... but the problem is that it would display something like this if I was missing city or zip:
" , CA "
Then I tried to make this code work for me:
var fields =["Case City", "Case Sate", "Case Zip Code"]; var values = []; for (var i in fields) { var f = this.getField(fields); if (f==null) { console.println("Error! The field doesn't exist: " + fields); continue; } if (f.valueAsString!="") values.push(f.valueAsString); } event.value = values.join(", ");
but for some reason, the code isn't working... any idea where I went wrong?
Thanks
Copy link to clipboard
Copied
The latter code seems fine, although it will not yield the same results as your original code.
What happens when you use it? Are there error messages in the JS Console?
Copy link to clipboard
Copied
In the second script you are creating an array of individual field names, but are not accessing each individual field name.
I would look for a copy of the Adobe example of the PFN folder of forms and get a copy of the document level funcitons "fillin".
Copy link to clipboard
Copied
Concatinate 3 Fields is an example of your 2 approaches and a third using a custom fillin funciton. The fillin function is placed as a document level function.
Copy link to clipboard
Copied
It would be very helpful if your code was formatted corectly.
This code is quite good, just one thing wrong. Here is the corrected code (correctly formated)
The issue is that "getField" needs to access a single element in the field name array. The original code does not include the element reference.
var fields =["Case City", "Case Sate", "Case Zip Code"];
var values = [];
for (var i in fields) {
var f = this.getField(fields[i]);
if (f==null) {
console.println("Error! The field doesn't exist: " + fields);
continue;
}
if (f.valueAsString!="") values.push(f.valueAsString);
}
event.value = values.join(", ");
Copy link to clipboard
Copied
Hi Thom_Parker,
thanks for the code. However, there seem to be a few small glitches.
I need it to not display anything if the value for the *CITY* is missing.
but, if value for Zip is missing, it should still display <CITY>, <STATE>
Copy link to clipboard
Copied
What I did was format and fix the non-working code and point out where there was an error. This script displays the concatonation of the fields listed. This is a general purpose script.
To create the functionality you want you need a different script. Something more specific to what you've asked for.
You're first attempt is closer to the solution. What's needed of course are some "if" statments to test for the conditions you've specified.
Here's an article that discussed using the "if".
https://www.acrobatusers.com/tutorials/conditional-execution/
Copy link to clipboard
Copied
gkaiseril,
thanks for the samples.
I changed the code around a bit, I need it to be blank when its just CA... you had it show CA if it was blank.
But i ran into a strange issue. The code/field works fine when it's inside you PDF file. but when I either copy/paste the field into my PDF, or, copy just the code into a new field in my PDF, it stops working. I have triple checked that the fields being referenced are accurate, but no luck.... would love to know what I'm doing wrong.
here is a link to your PDF, with my modified code, which works fine:
https://www.dropbox.com/s/mbago7bzul4usyc/CocatinationWithDefault%20%281%29.pdf?dl=0
Here is a link to my PDF, see page 39 of the PDF (big text box center of page)... password is to dropbox link is "1234":
https://www.dropbox.com/s/u5t88c7oekvcolg/Case%20Binder%20-%20Intake%20v2020.02.23.pdf?dl=0
-Mark
Copy link to clipboard
Copied
JavaScript can be placed in more than a form field. The example uses a document level function that you did not copy.
If you open the JavaScrip console, use the key combination <Ctrl> + J the console will open, there should be a message that " fillin" is not defined. With Acrobat Pro you will find the access to document level functions in the Form tool under "More".
Copy link to clipboard
Copied
Ah, thanks for pointing it out. I didn't realize that you had code there.
Brought the code over into my PDF... got your code to work as you intended it. However, when I tried to tweak it to my liking, it would break the code every time.
Can you do me a favor and give me the code with a slightly different outcome...
Now, assuming that default value for Case State is "CA"... also assume that all fields, including Case State are reset by user with a click of a reset button.
currently, your sample PDF/code, it's displaying "CA" when no other string values are present. Instead, what I need is for it not to display anything if the values in the other fields are not entered. So basically either we have an address and it should display all of it, or it should be blank, and so that it can be handwritten in later...
in some pages, I'm trying to combine 4 strings (street, city, state, zip) and other times 3 strings (city, state, zip)...
ideally, the code should be robust so I can get it to work with either scenario with small tweaks.
Lastly, it is preferable if this can be done with a form script (maybe with an IF condition) rather than a whole document script.
Thanks in advance.