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

Drop Down Selection adding to Total

Explorer ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

I have created a Mechandise Oder Form the calculations for items and quantities selected arte working properly.  I have a drop down menu "SHIPPING" with the variable shipping prices based on quantity of merchandise purchased.  I have tried several scripts but am nit getting the selected shipping option to add to the sum total (check box "TOTAL") of the purchased mechandise.

Please advise.

 

var q = Number(this.getField("TOTAL").value);

var s = this.getField("SHIPPING").valueAsString;

var total = 0;

if(s == “$16 (1-4 ITEMS)”)

total = 16;

else if(s == “$22 (5-9 ITEMS)”)

total = 22;

else if(s == “$38 (10-15 ITEMS)”)

total = 38;

else if(s == “$45 (16+ ITEMS)”)

total = 45;

event.value = q+total;

 

TOPICS
General troubleshooting , How to , JavaScript

Views

1.3K

Translate

Translate

Report

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

correct answers 6 Correct answers

Community Expert , Mar 16, 2021 Mar 16, 2021

He/She just uses dropdown as string to determine price in variable, easier would be to just add price as export value.

What exactly is problem with script? Press CTRL+J and paste your code in debugger to check for errors,

Here is your code, I just fixed quotes and it works fine for me:

var q = Number(this.getField("TOTAL").value);

var s = this.getField("SHIPPING").valueAsString;

var total = 0;

if(s == "$16 (1-4 ITEMS)")

total = 16;

else if(s == "$22 (5-9 ITEMS)")

total = 22;

else if(s == "$3
...

Votes

Translate

Translate
Community Expert , Mar 16, 2021 Mar 16, 2021

Use this as "Custom calculation script" of "SHIPPING" field:

if(this.getField("RM").value == "SHIP")
event.target.readonly = false;
else event.target.readonly = true;

Votes

Translate

Translate
Community Expert , Mar 16, 2021 Mar 16, 2021

In your first script change last line:

event.value = q+total;

with:

if(this.getField("RM").value == "PICK UP")
event.value = "";
else
event.value = q+total;

 

Votes

Translate

Translate
Community Expert , Mar 16, 2021 Mar 16, 2021

If you want to reset "SHIPPING" when "PICK UP" is selected change this line:

event.target.readonly = true;}

with
event.target.readonly = true;
event.value = "";}

Votes

Translate

Translate
Community Expert , Mar 16, 2021 Mar 16, 2021

If you revert changes I posted in my last post, does it still happen? if yes can you share your file?

Votes

Translate

Translate
Explorer , Mar 16, 2021 Mar 16, 2021

We removed event.value = ""; from the end of the script for the "SHIPPING" dropdown list and it works perfect!

 

Thank you for all your help!

Votes

Translate

Translate
Community Expert ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

Check your quotation marks:

"TOTAL"

$22 (5-9 ITEMS)

they need to be same as the ones around TOTAL ""

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

All quotes are now the same throughout the script, but It is still rejectiong.

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

++Adding to the always valuable guidance of NesaNurani,

 

I don't understand why variable q is formatted as Number while variable total declares a value as 0  snd then is changed on every conditional statement... don't you think this is creates a  problem in the subsequent if/else if statements?

 

Also, are q, s and total variables used in other custom calculations with other formfield objects?

 

 

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

He/She just uses dropdown as string to determine price in variable, easier would be to just add price as export value.

What exactly is problem with script? Press CTRL+J and paste your code in debugger to check for errors,

Here is your code, I just fixed quotes and it works fine for me:

var q = Number(this.getField("TOTAL").value);

var s = this.getField("SHIPPING").valueAsString;

var total = 0;

if(s == "$16 (1-4 ITEMS)")

total = 16;

else if(s == "$22 (5-9 ITEMS)")

total = 22;

else if(s == "$38 (10-15 ITEMS)")

total = 38;

else if(s == "$45 (16+ ITEMS)")

total = 45;

event.value = q+total;

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

That works!  I'm combing through to see if I can find my error.  Thank you!

 

My other question is I have a two Radio buttons "RM" one shoice is for pick up "PICK UP" and one for ship "SHIP" how can I activate the dropdown list "SHIPPING" by selecting radio button "SHIP"

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

By "activate" you mean it's set to read only and you want it to be editable if RM "SHIP" is selected?

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Yes, only be able to choose "SHHIPPING" if "SHIP" is slected

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Use this as "Custom calculation script" of "SHIPPING" field:

if(this.getField("RM").value == "SHIP")
event.target.readonly = false;
else event.target.readonly = true;

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

That works! 

 

Now if the "SHIPPING" is activated and an amount chosen the "TOTAL + Shipping" does not reset or unactivate if the user shanges their selection to "PICK UP"

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

In your first script change last line:

event.value = q+total;

with:

if(this.getField("RM").value == "PICK UP")
event.value = "";
else
event.value = q+total;

 

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

If you want to reset "SHIPPING" when "PICK UP" is selected change this line:

event.target.readonly = true;}

with
event.target.readonly = true;
event.value = "";}

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Thank you!  

 

Now when I select the shipping option, number of items to ship, and tab over to get the total plus shipping, the selection made in the drop down list goes away.  The total is correct but I can no longer see which list item was chosen.  How do I alter the script to keep list item chosen visable?

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Basically the dropdown list is not visible until you hit the drop down button, but after the choice is picked that choice is not visible.

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Do you have any code on the form that sets the dropdown value?  Can you post your form? From reading these posts it seems likely there could be some extraneous code floating about.  If we could see the form it would all become clear. 

 

 

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

Votes

Translate

Translate

Report

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

If you revert changes I posted in my last post, does it still happen? if yes can you share your file?

Votes

Translate

Translate

Report

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
Explorer ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

LATEST

We removed event.value = ""; from the end of the script for the "SHIPPING" dropdown list and it works perfect!

 

Thank you for all your help!

Votes

Translate

Translate

Report

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