Can you limit a combo box's options based on the value of another combo box?

Explorer ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

Referring to my screenshot, I'm wondering if it's possible to limit the options of of the second combo box based on the option chosen in the first one. So that you can't have a situation where the combo box number is smaller than the first combo box (e.g Prescription # 4 of 2). Is this possible?

 

danielw42205661_0-1663639090045.png

 

TOPICS
PDF forms

Views

67

Likes

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

correct answers 1 Correct answer

Community Expert , Sep 20, 2022 Sep 20, 2022

You can use this code as the custom Validation script of the second field (you didn't specify the field names, so I assumed the first one is called "Box1", adjust it in the second line of the code as necessary):

 

if (event.value!=event.target.defaultValue) {
	var box1 = this.getField("Box1");
	if (box1.valueAsString==box1.defaultValue) {
		app.alert("You must first select the first value.");
		event.rc = false;
	} else {
		var v1 = Number(box1.valueAsString);
		if (Number(event.value)<v1) {
			
...

Likes

Translate

Translate
Enthusiast ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

So you want only higher numbers to appear in second dropdown field?

If you select 5 only 6,7,8,9,10 should be in second field?

What if you select 10 in first field?

Likes

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
Explorer ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

Well I guess I should have said the same number or higher. So if 5 is first field, second field should only allow 5,6,7,8,9,10. So you can have 10 of 10. 

Likes

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 ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

If you select default value, do you want second dropdown to be empty or populated with numbers from 1-10?

What is the name of second field?

Likes

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 ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

You can use this code as the custom Validation script of the second field (you didn't specify the field names, so I assumed the first one is called "Box1", adjust it in the second line of the code as necessary):

 

if (event.value!=event.target.defaultValue) {
	var box1 = this.getField("Box1");
	if (box1.valueAsString==box1.defaultValue) {
		app.alert("You must first select the first value.");
		event.rc = false;
	} else {
		var v1 = Number(box1.valueAsString);
		if (Number(event.value)<v1) {
			app.alert("You must select a value equal to, or higher than, the first value.");
			event.rc = false;
		}
	}
}

 

Likes

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
Explorer ,
Sep 21, 2022 Sep 21, 2022

Copy link to clipboard

Copied

Thanks so much @try67 . Exactly what I needed.  

Likes

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 ,
Sep 22, 2022 Sep 22, 2022

Copy link to clipboard

Copied

LATEST

I would also add a command to reset the second field when a selection is made in the first one, otherwise the user could go back to it and change it to an invalid value. To do that, enter the following as the custom Validation script of Box1 (again, adjusting the field names as needed):

 

this.resetForm(["Box2"]);

Likes

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

Make content for your business needs with Adobe Express.

Get started easily with free templates: