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

Using If/Then/Else statements, what is the code to return specific text with a calculated value?

New Here ,
Feb 13, 2017 Feb 13, 2017

Below is the code I wrote for PDF form.  I do not want a line of text to appear unless IF statement is false.

var a = Number(this.getField("A").value);

var b = Number(this.getField("1").value);

if (b==0) event.value = "";

else event.value = "1 CARTON OF",(a%b);

I want the end result to be either blank or "1 carton of " (calculated number).

Is this possible?

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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 13, 2017 Feb 13, 2017

Yes. Change the last line of your code to:

else event.value = "1 CARTON OF" + (a/b);

View solution in original post

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 ,
Feb 13, 2017 Feb 13, 2017

Yes. Change the last line of your code to:

else event.value = "1 CARTON OF" + (a/b);

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 ,
Feb 13, 2017 Feb 13, 2017

Almost there...thank you.  That number is supposed to be a remainder of total number of pieces divided by the quantity per carton.  It is designed to give me a partial carton quantity on a packing list.

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 ,
Feb 13, 2017 Feb 13, 2017

In that case use the modulus operator ("%"), which you originally had. I changed it to the division operator ("/") because I had assumed (incorrectly) that that's what you mean to calculate.

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 ,
Feb 13, 2017 Feb 13, 2017

Glad I could find an expert at this.

I now have a dropdown menu of various ship to locations. I want to have the full address appear in another text box on my form when a certain location is selected from the menu.

Ideas?

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 ,
Feb 13, 2017 Feb 13, 2017

To learn how to do that you should read this tutorial:

https://acrobatusers.com/tutorials/change_another_field

Or you can use this tool I've developed, exactly for this task:

Custom-made Adobe Scripts: Acrobat -- Populate Fields From Dropdown

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 ,
Feb 14, 2017 Feb 14, 2017

I feel I am almost there.  Getting an syntax error that I am missing a ":" after property id 2: at line 3.

// Place all prepopulation data into a single data structure

var DeptData = { 6540 STONEGATE:{ ADDRESS: "LUTRON ELECTRONICS 6540 STONEGATE ROAD ALLENTOWN PA 18106"},

                 6560 STONEGATE:{ ADDRESS: "LUTRON ELECTRONICS 6560 STONEGATE ROAD ALLENTOWN PA 18106"},

                 COOPERSBURG:{ ADDRESS: "LUTRON ELECTRONICS 7200 SUTER ROAD COOPERSBURG PA 18036"},

                 EL PASO:{ ADDRESS: "LUTRON C/O SPACE BORDER LOGISTICS 9560 JOE RODRIGUEZ DR. EL PASO TX 79927"},

                 PUERTO RICO:{ ADDRESS: "LUTRON SM INC. CARR #909 KM 0.2 INDUSTRIAL PARK MARIANA 2 HUMACAO PR 00792"}};

function SetFieldValues(cDeptName)

{

  this.getField("ADDRESS").value = DeptData[cDeptName].ADDRESS;

 

}

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 ,
Feb 14, 2017 Feb 14, 2017

You must put quotes around any text that contains a space, and you should

probably do it in all cases anyway.

On Tue, Feb 14, 2017 at 4:27 PM, DKPrintConcepts <forums_noreply@adobe.com>

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 ,
Feb 14, 2017 Feb 14, 2017

I don't understand. There ARE quotes where they should be.

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 ,
Feb 14, 2017 Feb 14, 2017

No, there aren't. You need to put quotes around the names of each literal object as well, such as "6560 STONEGATE".

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 ,
Feb 14, 2017 Feb 14, 2017

OH...gotcha.  Almost there.

Obviously, these are ship to addresses.  how can I put breaks in so the address appears like below?

LUTRON ELECTRONICS

6560 STONEGATE ROAD

ALLENTOWN, PA 18106

Again...thank you so much for your patience.

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 ,
Feb 14, 2017 Feb 14, 2017

When you want to insert a line-break use this code "\n", like so:

LUTRON ELECTRONICS\n6560 STONEGATE ROAD\nALLENTOWN, PA 18106

And of course you need to set the field as Multiline.

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 ,
Feb 14, 2017 Feb 14, 2017

AHHHHHHHHHHHHHHH...driving me crazy.

I added another item to the dropdown and now it won't work.

var SHIPTO = {{"SELECT SHIP TO ADDRESS":{ ADDRESS: " "},

"6540 STONEGATE":{ ADDRESS: "LUTRON ELECTRONICS\n6540 STONEGATE ROAD\nALLENTOWN, PA 18106"},

"6560 STONEGATE":{ ADDRESS: "LUTRON ELECTRONICS\n6560 STONEGATE ROAD\nALLENTOWN, PA 18106"},

"COOPERSBURG":{ ADDRESS: "LUTRON ELECTRONICS\n7200 SUTER ROAD\nCOOPERSBURG, PA 18036"},

"EL PASO":{ ADDRESS: "LUTRON C/O SPACE BORDER LOGISTICS\n9560 JOE RODRIGUEZ DR.\nEL PASO, TX 79927"},

"PUERTO RICO":{ ADDRESS: "LUTRON SM INC.\nCARR #909 KM 0.2\nINDUSTRIAL PARK MARIANA 2\nHUMACAO, PR 00792"}};

function SetFieldValues(cSHIPTO)

{

  this.getField("ADDRESS").value = DeptData[cSHIPTO].ADDRESS;

 

}

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 ,
Feb 14, 2017 Feb 14, 2017

There's a syntax error in your code. Drop one of the first opening curly brackets in the first line.

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 ,
Feb 14, 2017 Feb 14, 2017

I tried that...still will not work.  All selections return the same address.

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 ,
Feb 14, 2017 Feb 14, 2017

Why did you change the variable name from DeptData to SHIPTO?

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 ,
Feb 14, 2017 Feb 14, 2017
LATEST

I don't know.  I changed it back and it works.  Genius!!!  Thank you.

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 ,
Feb 13, 2017 Feb 13, 2017

It WORKS!!!!!!  Thank you for all your help.

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