Skip to main content
Known Participant
October 8, 2024
Answered

Prefill one field depending on 2 different drop downs

  • October 8, 2024
  • 1 reply
  • 589 views

I'm trying to do a 'if this dropdown is xyz AND this other drop down is abc, then text needs to be .....

The variables are both drop downs. The below works ok until the bits in blue are added. Apologies if the below isn't pretty, but please could someone correct where I've gone wrong.

 

var OffCode = this.getField("O.aff_es_:prefill").value;
var InstChoice = this.getField("Installation choice_es_:prefill").value
if (OffCode=="...") event.value = " ";
else if (OffCode=="FSPE") event.value = "Je ne souhaite ........";
else if (OffCode=="FSFI") event.value = "Je ne souhaite ........";
else if (OffCode=="FSPB") event.value = "Je ne souhaite .........";
else if (OffCode=="FSPB") event.value &&(InstChoice=="Pas d’équipement(s) à installer") event.value = "Je ne souhaite ........";
else event.value = " ";

This topic has been closed for replies.
Correct answer try67

Your syntax is off. The entire IF condition has to be in parentheses and the && operator has to be located between the two conditions. Try this:

 

else if (OffCode=="FSPB" && InstChoice=="Pas d’équipement(s) à installer") event.value = "Je ne souhaite ........";

 

However, you also have a logical error, because if OffCode=="FSPB" then the previous condition before that line will be true, and you will never reach it. To solve it you can use nesting, like this:

 

else if (OffCode=="FSPB") {
	if (InstChoice=="Pas d’équipement(s) à installer") event.value = "Je ne souhaite ........";
	else event.value = "Je ne souhaite .........";
}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 8, 2024

Your syntax is off. The entire IF condition has to be in parentheses and the && operator has to be located between the two conditions. Try this:

 

else if (OffCode=="FSPB" && InstChoice=="Pas d’équipement(s) à installer") event.value = "Je ne souhaite ........";

 

However, you also have a logical error, because if OffCode=="FSPB" then the previous condition before that line will be true, and you will never reach it. To solve it you can use nesting, like this:

 

else if (OffCode=="FSPB") {
	if (InstChoice=="Pas d’équipement(s) à installer") event.value = "Je ne souhaite ........";
	else event.value = "Je ne souhaite .........";
}
jlehaneAuthor
Known Participant
October 8, 2024

Thank you as always @try67 - much appreciated