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;
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
...
Use this as "Custom calculation script" of "SHIPPING" field:
if(this.getField("RM").value == "SHIP")
event.target.readonly = false;
else event.target.readonly = true;
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;
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 = "";}
If you revert changes I posted in my last post, does it still happen? if yes can you share your file?
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!
Copy link to clipboard
Copied
Check your quotation marks:
"TOTAL"
“$22 (5-9 ITEMS)”
they need to be same as the ones around TOTAL ""
Copy link to clipboard
Copied
All quotes are now the same throughout the script, but It is still rejectiong.
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?
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;
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"
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?
Copy link to clipboard
Copied
Yes, only be able to choose "SHHIPPING" if "SHIP" is slected
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;
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"
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;
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 = "";}
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?
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.
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.
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?
Copy link to clipboard
Copied
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!