Skip to main content
Participant
August 26, 2023
Answered

Validation Script Help - Want Drop Down Choice to Autofill Another Field

  • August 26, 2023
  • 2 replies
  • 1929 views

I have set a list of drop-down choices in my sponsorship field and I want my unit price to autofill based on what is selected in the sponsorship field.

 

In the unit price field  properties, I have entered this in the custom validation:

 if(this.getField("Sponsorship1.0").valueAsString=="AuSome Evening Premiere Sponsorship") event.value = "$7,500";
else event.value = ""

 

How do I add more than one validation script for the same field?

I have been googling trying to figure it out and I am still not sure. Any help is appreciated!!!

This topic has been closed for replies.
Correct answer Nesa Nurani

This won't work as a validation script of a text field, instead use it as a custom calculation script.

There is an easier way, just add prices as export values of choices in dropdown field, then in text field as custom calculation script use this:

event.value = this.getField("Sponsorship1.0").value;

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
August 27, 2023

This won't work as a validation script of a text field, instead use it as a custom calculation script.

There is an easier way, just add prices as export values of choices in dropdown field, then in text field as custom calculation script use this:

event.value = this.getField("Sponsorship1.0").value;

Participant
August 27, 2023

Thanks so much! It is working now! 

 

I entered the export values and now the unit price auto-populates based on the drop downs. Is there a way to make it so if a certain menu item is picked, they can enter whatever text they want in the unit price field. Basically overrided the export value if needed. I have a couple sponsorship options where they can choose how much they want to give and I want to be able to type that amount in my unit price field. 

Nesa Nurani
Community Expert
Community Expert
August 27, 2023

Yes, you can use this:

if(this.getField("Sponsorship1.0").valueAsString !== "Free text")
event.value = this.getField("Sponsorship1.0").value;

 

Replace "Free text" with choice you wish user to be able to enter text manually (you don't have to add export value for that choice)

try67
Community Expert
Community Expert
August 26, 2023

You can't add more than one validation script, but you can add multiple conditions to your code.

The structure for that would be something like this:

 

var sponsorship = this.getField("Sponsorship1.0").valueAsString;
if (sponsorship=="AuSome Evening Premiere Sponsorship") event.value = "$7,500";
else if (sponsorship=="Something else") event.value = "$10,500";
else if (sponsorship=="Something else #2") event.value = "$1,500";
// etc.
else event.value = ""
Participant
August 27, 2023

Thank you!