Skip to main content
Inspiring
January 19, 2024
Answered

Switch statement for pdf js

  • January 19, 2024
  • 1 reply
  • 2612 views

I am not a correct output for the following script:

 

var floor == this.getField("Floor Location").value;
var storeys == this.getField("Storeys").value;
var zero, oneStorey, twoStoreys, none, B, M, S;

if (storeys == "One storey") {
  storeys = oneStorey;
}
if (storeys == "Two storeys") {
  storeys = twoStoreys;
}

if (floor == "B") {
  floor = B;
}
if (floor == "M") {
  floor = M;
}
if (floor == "2nd") {
  floor = S;
}

switch (true) {

  case ((storeys == twoStoreys) && (floor == B)):
    event.value = "17";
    break;
  case ((storeys == twoStoreys) && (floor == M)):
    event.value = "11";
    break;
  case ((storeys == twoStoreys) && (floor == S)):
    event.value = "1";
    break;
   case ((storeys == oneStorey) && (floor == B)):
    event.value = "11";
    break;
  case ((storeys == oneStorey) && (floor == M)):
    event.value = "1";
    break;
  default:
        event.value = floor;
        break;}
 
This topic has been closed for replies.
Correct answer Khaliquzzaman Katchi

You've made it unnecessarily complicated (and incorrect).

See attached.


Never mind I found the bug: the statement should be changed to 

"else if((storeys == "Two storeys") && (floor == "2nd"))
event.value = "1"

Thank you for putting me in the right track.

1 reply

Nesa Nurani
Inspiring
January 19, 2024

When you're assigning values to variables, you should use a single equal sign (=) instead of a double equal sign (==).

Why so many variables in this line: var zero, oneStorey, twoStoreys, none, B, M, S;

You don't use 'zero' or 'none' variable at all, you are setting floor variable to 'M' , 'B' or 'S' variable, but you didn't assign anything to them.

Inspiring
January 19, 2024

I have made some corrections according to your comments but I still do not get the outputs I am looking for.

 

I am also attaching the pdf file so that you can see the outcome.

Kk
Inspiring
January 19, 2024

Thank you, that was a huge improvement over my script.

 

However, the case "else if((storeys == "Two storeys") && (floor == "S"))
event.value = "1";" does not respond. Could you help?

Thank you

Kk