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

make a selection in a drop down field based on the value of two other field numbers

New Here ,
Feb 20, 2025 Feb 20, 2025

I have a drop down field (A or B) that needs to be selected based on the value of two other fields

 

if C > D Dropdown = A

If C < D Drowpdown = B

 

How can I write this?

I am definitely new to this and have googled quite a few other answers, but this one is hard to narrow down. 

Thx in advance

TOPICS
How to
364
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 21, 2025 Feb 21, 2025

Yes. Replace this line:

event.value = (numC >= numD) ? "Accept" : "Reject";

 

With:

 

if (numC >= numD) {
	event.value = "Accept";
	event.target.textColor = color.green;
} else { 
	event.value = "Reject";
	event.target.textColor = color.red;
}

View solution in original post

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 20, 2025 Feb 20, 2025

You could use a text field instead of dropdown if you only have two values "A" and "B", and use this as custom calculation script of that text field:

var c = this.getField("C").valueAsString;
var d = this.getField("D").valueAsString;

if (c && d) {
 var numC = Number(c);
 var numD = Number(d);

 if (!isNaN(numC) && !isNaN(numD)) {
  event.value = numC > numD ? "A" : numC < numD ? "B" : "";}} 
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
New Here ,
Feb 20, 2025 Feb 20, 2025

I udated the letters to match the box names and copied this into the script box and it said:

syntaxError: missing ; before statement 5: at line 6

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 20, 2025 Feb 20, 2025

What should the field's value be if C equals D?

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
New Here ,
Feb 20, 2025 Feb 20, 2025

a = Accept

b = Reject

c = MaxGrossRent

d = GrossRent

 

 

GrossRent>MaxGrossRent=Accept

GrossRent<MaxGrossRent=Reject

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
New Here ,
Feb 20, 2025 Feb 20, 2025

My bad. if C=D it is Accept

 

GrossRent=>MaxGrossRent=Accept

GrossRent<MaxGrossRent=Reject

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 20, 2025 Feb 20, 2025

What about if one of those fields has a value and the other doesn't, or both don't have a 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
New Here ,
Feb 20, 2025 Feb 20, 2025

Well, once someone fills out the other areas, the value in those fields will be a number based on the calculation in there. 

 

if the form is first opened and all of the fields are 0, the accept/reject field can be blank. 

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 20, 2025 Feb 20, 2025

Use this code as the custom calculation script of your field (based on Nesa's code from earlier):

 

var c = this.getField("GrossRent").valueAsString;
var d = this.getField("MaxGrossRent").valueAsString;

if (c && d) {
    var numC = Number(c);
    var numD = Number(d);
    event.value = (numC >= numD) ? "Accept" : "Reject";
} 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
New Here ,
Feb 20, 2025 Feb 20, 2025

Thank you. I got the form to update when i update the other numbers. just waiting to hear back from someone to verify the numbers and calculations are correct. 

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
New Here ,
Feb 21, 2025 Feb 21, 2025

Thanks to you both. I got the form updated and checked and it is working perfectly for what i need! 

 

One last thing. Is there a way to make the words show up in a certain color? Green for Accept - Red for Reject?

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 21, 2025 Feb 21, 2025

Yes. Replace this line:

event.value = (numC >= numD) ? "Accept" : "Reject";

 

With:

 

if (numC >= numD) {
	event.value = "Accept";
	event.target.textColor = color.green;
} else { 
	event.value = "Reject";
	event.target.textColor = color.red;
}
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
New Here ,
Feb 25, 2025 Feb 25, 2025
LATEST

Perfect!!!!! Thanks BUNCHES!

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