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

3 dropdown menus to auto populate 1 textbox depending on selection

Community Beginner ,
Feb 28, 2024 Feb 28, 2024

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;

 

}

 

 

}

 

TOPICS
How to , JavaScript , PDF

Views

370

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

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

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

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

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

Copy link to clipboard

Copied

Post your code.

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

Copy link to clipboard

Copied

Screenshot 2024-02-29 at 10.08.26 AM.png

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

Copy link to clipboard

Copied

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

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

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

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

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

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

Copy link to clipboard

Copied

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

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

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;

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

Copy link to clipboard

Copied

What script do you use?

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

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. 

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

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.

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

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

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

Copy link to clipboard

Copied

LATEST

Add "else" before:

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

It works fine for me.

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