Skip to main content
danielw42205661
Known Participant
September 20, 2022
Answered

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

  • September 20, 2022
  • 3 replies
  • 970 views

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?

 

 

This topic has been closed for replies.
Correct answer try67

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

 

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 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) {
			app.alert("You must select a value equal to, or higher than, the first value.");
			event.rc = false;
		}
	}
}

 

danielw42205661
Known Participant
September 22, 2022

Thanks so much @try67 . Exactly what I needed.  

Nesa Nurani
Community Expert
Community Expert
September 20, 2022

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?

Inspiring
September 20, 2022

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?

danielw42205661
Known Participant
September 20, 2022

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.