Skip to main content
stepheng54012748
Known Participant
October 23, 2024
Answered

Javascript question

  • October 23, 2024
  • 1 reply
  • 472 views

Hello,

 

I have three buttons that can potentially be checked on a form i create.  I'm close to getting the results to populate in another field but I think because i have 4 different possible outcomes i can't seem to get it right.  The bottom line is if checkbox 1 is selected (cb144) then should yield a result R, if checkbox 2 is selected then should yield a result N, if checkbox 3 is selected then should yield a result P and if no box is selected then it should yield nothing in the field.  Below is the script i've written and obviously it's not working.  Can anyone help me out finishing the following script?

 

var theField = this.getField("cb144");
var theValue = theField.value;
var theField2 = this.getField("cb145");
var theValue2 = theField2.value;
var theField3 = this.getField("cb146");
var theValue3 = theField3.value;


if (theValue == "Resident") {
this.getField("a14a4").value= "R";
}
if (theValue2 == "Non-Resident") {
this.getField("a14a4").value= "N";
}
if (theValue3 == "Part Year") {
this.getField("a14a4").value= "P";
}
else {
this.getField("a14a4").value= "";
}

This topic has been closed for replies.
Correct answer try67

You need to add "else" before all the if-statements, except for the first one, so they are linked in a single thread, and not separate commands. As it stands, only your last if-else statement has any effect. All the ones before it get overwritten no matter what the values are.

1 reply

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

You need to add "else" before all the if-statements, except for the first one, so they are linked in a single thread, and not separate commands. As it stands, only your last if-else statement has any effect. All the ones before it get overwritten no matter what the values are.

stepheng54012748
Known Participant
October 23, 2024

YOU ARE AWESOME!!!!  THANK YOU.