Copy link to clipboard
Copied
i have several text boxes that has information in them and I would like to add that information up and have it displayed in a different text box. example: Text box 1: 6 baseballs, 4 bats, 3 gloves, Text box 2: 4 baseballs, 2 bats,4 gloves; Text box 3: 2 baseballs, 1 bat, 2 gloves. Text box 4 would then read: 12 baseballs, 7 bats, 9 gloves. Is there a script that i could have this done in adobe acrobat pro? Thank you in advance for your help.
Copy link to clipboard
Copied
This can be done with a script, yes, but it's not a simple task. You would need to split the strings then search them for matching terms. Then you would need to collect all of the results and create a new string for the total field.
It would be much easier if there was a separate field for each item...
Copy link to clipboard
Copied
try67, I am unable to separate the fields, the format of the document has to remain the same. That is why I was wanting to know if a script would be able to perform such a task
Copy link to clipboard
Copied
OK, then see the first couple of sentences in my previous reply.
Copy link to clipboard
Copied
Then you will have to parse the text boxes into the various categories. JavaScript, like the majority of computer languages is case sensitive and does not deal with the combination of text and numbers very easily.
It is possible to split the entry by the spaces. Now if the text is always entered in # type of item order, one can look at the element pairs and accumulate the data as long as the spelling and capitalization is correct. You may also need to decide how you will handle errors or items entered not as you expected them or not considered as part or your inventory when the form was designed.
Copy link to clipboard
Copied
ok, I have been trying to do this script and I can't seem to get anywhere with it. Can anyone point me in the right direction or have a similar script that could get me started. Thank you
Copy link to clipboard
Copied
Try the following script for the custom Calculation for the 4th field:
var cText1 = this.getField("Text1").valueAsString;
var cText2 = this.getField("Text2").valueAsString;
var cText3 = this.getField("Text3").valueAsString;
// convert text sriings into arrays;
var aText1 = cText1.split(" ");
var aText2 = cText2.split(" ");
var aText3 = cText3.split(" ");
var nBaseballs = 0;
var nBats = 0;
var nGloves = 0;
if(aText1.length == 6)
{
nBaseballs = nBaseballs + Number(aText1[0]);
nBats = nBats + Number(aText1[2]);
nGloves = nGloves + Number(aText1[4]);
}
else
{
app.alert("Entry must be \"# Baseballs, # Bats, # Gloves\" \nNot " + cText1, 1, 0);
}
if(aText2.length == 6)
{
nBaseballs = nBaseballs + Number(aText2[0]);
nBats = nBats + Number(aText2[2]);
nGloves = nGloves + Number(aText2[4]);
}
else
{
app.alert("Entry must be \"# Baseballs, # Bats, # Gloves\" \nNot " + cText2, 1, 0);
}
if(aText3.length == 6)
{
nBaseballs = nBaseballs + Number(aText3[0]);
nBats = nBats + Number(aText3[2]);
nGloves = nGloves + Number(aText3[4]);
}
else
{
app.alert("Entry must be \"# Baseballs, # Bats, # Gloves\" \nNot " + cText3, 1, 0);
}
event.value = util.printf("%,001.0f Baseballs, %,101.0f Bats, %,001.0f Gloves", nBaseballs, nBats, nGloves);
I had to add some validation to the script because the one of the entry's text format was not consistent the required format of the data entered. More scripting could be added to make sure the items are entered in the correct order.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now