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

Script won't give a result. Trying to assign a value to a var with a switch function

New Here ,
Aug 08, 2019 Aug 08, 2019

Not sure what I am doing wrong here, but I think I am close. I am trying to have a function find the smaller of either one field entered by the user of the form or another set of numbers based on a dropdown menu.

I am not sure where I am going wrong here, I think I am using the switch function incorrectly to assign a value to one of my variables, but I have no idea how to fix it:

var z = this.getField ("Line1");

var y = this.getField ("Dropdown3").value;

var x = (function(y) {

switch(y) {

          case "S":

               x = 39375

               break;

          case "MFJ":

               x = 78750

               break;

          case "MFS":

               x = 39375

               break;

          case "HH":

               x = 52750

               break;

     }

})

event.value = Math.min(z.value, x.value);

this.getField ("Line11")=event.value;

The cases are the different values of the dropdown. That notation has worked in other fields, but I have never tried to use it to assign a value to a variable, only to find the output of a field. Line1 is a field where a user enters a number.

What am I doing wrong? I am not very well versed in javascript.

TOPICS
Acrobat SDK and JavaScript , Windows
663
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

correct answers 1 Correct answer

Community Expert , Aug 08, 2019 Aug 08, 2019

Try this:

var z = this.getField ("Line1");

var y = this.getField ("Dropdown3").value;

var x = 0;

switch(y) {

          case "S":

               x = 39375;

               break;

          case "MFJ":

               x = 78750;

               break;

          case "MFS":

               x = 39375;

               break;

          case "HH":

               x = 52750;

               break;

     }

event.value = Math.min(z.value, x);

Translate
Community Expert ,
Aug 08, 2019 Aug 08, 2019

Try this:

var z = this.getField ("Line1");

var y = this.getField ("Dropdown3").value;

var x = 0;

switch(y) {

          case "S":

               x = 39375;

               break;

          case "MFJ":

               x = 78750;

               break;

          case "MFS":

               x = 39375;

               break;

          case "HH":

               x = 52750;

               break;

     }

event.value = Math.min(z.value, x);

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 ,
Aug 08, 2019 Aug 08, 2019

That worked, thank you!

Why do you have to define var x as 0 first if you don't mind me asking?

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 ,
Aug 08, 2019 Aug 08, 2019
LATEST

When you want you can remove the zero.

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