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

Switch statement for pdf js

Community Beginner ,
Jan 18, 2024 Jan 18, 2024

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;}
 
Kk
TOPICS
JavaScript
1.9K
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 Beginner ,
Jan 19, 2024 Jan 19, 2024

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.

Kk

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 ,
Jan 18, 2024 Jan 18, 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.

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 ,
Jan 19, 2024 Jan 19, 2024

Also, your use of the switch command doesn't make sense. Why not simply use if-else if?

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 Beginner ,
Jan 19, 2024 Jan 19, 2024

Because the switch statement I used is equivalent and simpler to in my script use than many "if" and "else" which could be confusing and there are too many combinations to deal with. Anyhow I tried that approach also and it does not work either. I am uploading the file for your own analysis.

Kk
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 Beginner ,
Jan 19, 2024 Jan 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
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 ,
Jan 19, 2024 Jan 19, 2024

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

See attached.

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 Beginner ,
Jan 19, 2024 Jan 19, 2024

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.

Kk
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 Beginner ,
Jan 19, 2024 Jan 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
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 Beginner ,
Jan 19, 2024 Jan 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

Kk
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 ,
Jan 19, 2024 Jan 19, 2024
LATEST

So it's working well, or not?

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