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

New Here ,
Aug 08, 2019

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

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);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

56

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Aug 08, 2019

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

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);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

57

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 08, 2019 0
Adobe Community Professional ,
Aug 08, 2019

Copy link to clipboard

Copied

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);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2019 0
New Here ,
Aug 08, 2019

Copy link to clipboard

Copied

That worked, thank you!

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2019 0
Adobe Community Professional ,
Aug 08, 2019

Copy link to clipboard

Copied

When you want you can remove the zero.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2019 0