Copy link to clipboard
Copied
I am trying to get a 3 dropdown menus to autopopulate a text box dependant on the choice selected in the dropdown.
This is formula that I have so far, when I do it for one of the dropdown menu's it works fine, but I'm having issues when trying to add another dropdown menu.
Can you please advise.
The formula is below
var Item = this.getField("Sponsorship Level").value;
switch(Item){
case "Production Sponsor (Musical)":
event.value = "7500";
break;
case "Production Sponsor (Play)":
event.value = "6000";
break;
case "Benefactor":
event.value = "3600";
break;
case "Benefactor B&W Ad":
event.value = "3500";
break;
case "Backer":
event.value = "2500";
break;
case "Backer B&W Ad":
event.value = "2375";
break;
}
}
Copy link to clipboard
Copied
Don't use a switch command. Use an if statement with multiple conditions, like this:
var v1 = this.getField("Dropdown1").valueAsString;
var v2 = this.getField("Dropdown1").valueAsString;
var v3 = this.getField("Dropdown1").valueAsString;
if (v1=="A" && v2=="A" && v3=="A") event.value = "A-A-A";
else if (v1=="A" && v2=="A" && v3=="B") event.value = "A-A-B";
else if (v1=="B" && v2=="A" && v3=="C") event.value = "B-A-C";
// etc.
else event.value = "";
Copy link to clipboard
Copied
Thanks! When I use this formula and plug in my labels it says:
Syntax Error: missing ) after argument list
3: at line 4
Copy link to clipboard
Copied
Post your code.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The quotes inside the text have to be escaped, by adding a back-slash before them.
Copy link to clipboard
Copied
I don't quite understand what you mean. My code is below.
var v1 = this.getField("Sponsorship Levels").valueAsString;
var v2 = this.getField("Ad Sizes").valueAsString;
var v3 = this.getField(Premium Position").valueAsString;
if (v1=="Production Sponsor (Musical)" && v2=="" && v3=="") event.value = "7500";
else if (v1=="Production Sponsor (Musical)" && v2=="FULL PAGE (4.67"w x7.67"h) COLOR" && v3=="Back Cover") event.value = "8500";
else if (v1=="Production Sponsor (Musical)" && v2=="FULL PAGE (4.67"w x7.67"h) COLOR" && v3=="Front Inside Cover") event.value = "8000";
else event.value = "";
Copy link to clipboard
Copied
Here, for example:
else if (v1=="Production Sponsor (Musical)" && v2=="FULL PAGE (4.67"w x7.67"h) COLOR" && v3=="Back Cover") event.value = "8500";
It needs to be:
else if (v1=="Production Sponsor (Musical)" && v2=="FULL PAGE (4.67\"w x7.67\"h) COLOR" && v3=="Back Cover") event.value = "8500";
Copy link to clipboard
Copied
good to know, thank you, that still didn't fix the syntax error though on line 4
Copy link to clipboard
Copied
You are also missing quote for Premium Position field:
var v3 = this.getField(Premium Position").valueAsString;
should be:
var v3 = this.getField("Premium Position").valueAsString;
Copy link to clipboard
Copied
What script do you use?
Copy link to clipboard
Copied
Update: if this makes my end goal more clear:
I have 3 different dropdown boxes
I need the dropdowns to feed into 1 text box
The ideal is to code this in a way where the each dropdown option would be able to have a numerical value conencted to it in the coding and add up as they choose their options.
On top of this, I would like to have the dropdown influence other dropdown menus.
Meaning:
Sponsorship Levels:
If you choose :
Production Sponsor (Musical) then the Ad Size option would be FULL PAGE (4.67"w x7.67"h) COLOR and the Premium Position options would be Back Cover, Front Inside Cover, Back Inside Cover
etc...
Copy link to clipboard
Copied
We understood. The code you were given will do that.
Copy link to clipboard
Copied
Thank you, However, when I copy the code and then put in the proper "titles" it gives me a syntax error or it doesn't populate the cost field.
Copy link to clipboard
Copied
So there are errors in your code. We pointed out several issues before. Did you solve them? If so, post your current code (as text only, please), for further help.
Copy link to clipboard
Copied
var v1 = this.getField("Sponsorship Levels").valueAsString;
var v2 = this.getField("Ad Sizes").valueAsString;
var v3 = this.getField("Premium Position").valueAsString;
if (v1=="Production Sponsor (Musical)" && v2=="" && v3=="") event.value = "7500";
else if (v1=="Production Sponsor (Musical)" && v2=="FULL PAGE (4.67\"w x7.67\"h) COLOR" && v3=="Back Cover") event.value = "8500";
else if (v1=="Production Sponsor (Musical)" && v2=="FULL PAGE (4.67\"w x7.67\"h) COLOR" && v3=="Front Inside Cover") event.value = "8000";
if (v1=="Production Sponsor (Play)" && v2=="" && v3=="") event.value = "6000";
else if (v1=="Production Sponsor (Play)" && v2=="FULL PAGE (4.67\"w x7.67\"h) COLOR" && v3=="Back Cover") event.value = "6500";
else if (v1=="Production Sponsor (Play)" && v2=="FULL PAGE (4.67\"w x7.67\"h) COLOR" && v3=="Front Inside Cover") event.value = "6250";
else event.value = "";
Copy link to clipboard
Copied
Add "else" before:
if (v1=="Production Sponsor (Play)" && v2=="" && v3=="") event.value = "6000";
It works fine for me.