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

3 dropdown menus to auto populate 1 textbox depending on selection

Community Beginner ,
Feb 28, 2024 Feb 28, 2024

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;

 

}

 

 

}

 

TOPICS
How to , JavaScript , PDF
1.2K
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 28, 2024 Feb 28, 2024

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 = "";
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 Beginner ,
Feb 29, 2024 Feb 29, 2024

Thanks! When I use this formula and plug in my labels it says:

 

Syntax Error: missing ) after argument list

3: at line 4

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 29, 2024 Feb 29, 2024

Post your code.

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 Beginner ,
Feb 29, 2024 Feb 29, 2024

Screenshot 2024-02-29 at 10.08.26 AM.png

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 29, 2024 Feb 29, 2024

The quotes inside the text have to be escaped, by adding a back-slash before them.

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 Beginner ,
Feb 29, 2024 Feb 29, 2024

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 = "";

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 29, 2024 Feb 29, 2024

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";

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 Beginner ,
Feb 29, 2024 Feb 29, 2024

good to know, thank you, that still didn't fix the syntax error though on line 4

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 29, 2024 Feb 29, 2024

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;

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 29, 2024 Feb 29, 2024

What script do you use?

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 Beginner ,
Feb 29, 2024 Feb 29, 2024

Update: if this makes my end goal more clear:

 

I have 3 different dropdown boxes

  • Sponsorship Level
  • Ad Size
  • Premium Positioning

 

I need the dropdowns to feed into 1 text box 

  • Cost

 

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...

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 29, 2024 Feb 29, 2024

We understood. The code you were given will do that.

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 Beginner ,
Feb 29, 2024 Feb 29, 2024

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. 

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 29, 2024 Feb 29, 2024

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.

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 Beginner ,
Feb 29, 2024 Feb 29, 2024

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 = "";

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 29, 2024 Feb 29, 2024
LATEST

Add "else" before:

if (v1=="Production Sponsor (Play)" && v2=="" && v3=="") event.value = "6000";

It works fine for me.

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