Skip to main content
Inspiring
July 5, 2021
Answered

Attempting to Generate calc based on Choice from DropDown Menu

  • July 5, 2021
  • 3 replies
  • 834 views

I am attempting to generate a value based on the chosen value of the DropDown Menu:
The DropDown Menu is labled: size

It contains these Items: Tiny, Small, Medium, Large, Huge

The DropDown Menu has Commit Selected value immediately

 

var s = this.getfield("size").value;
if (getField ("size").value == "Small")
event.value = (Strength1);
else if (getField ("size").value == "Medium")
event.value = ((Strength1)*(2));
else if (getField ("size").value == "Large")
event.value = ((Strength1)*(3));

This topic has been closed for replies.
Correct answer levid37094220

i fixed it using the followin, that I finally figured out:

var s = this.getField("size").value;
var n = this.getField("Strength1").value

if (s=="Small") {
event.value = n;
}
else if (s=="Medium") {
event.value = n*2;
}
else if (s=="Large") {
event.value = n*3;
}
else if (s=="Huge") {
event.value = n*4;
}
else if (s=="Tiny") {
event.value = n/2;
}

3 replies

try67
Community Expert
Community Expert
July 5, 2021

Use this:

 

var size = this.getField("size").valueAsString;
var strength1 = Number(this.getField("Strength1").valueAsString);
if (size == "Small")
	event.value = strength1;
else if (size == "Medium")
	event.value = strength1*2;
else if (s == "Large")
	event.value = strength1*3;
levid37094220AuthorCorrect answer
Inspiring
July 13, 2021

i fixed it using the followin, that I finally figured out:

var s = this.getField("size").value;
var n = this.getField("Strength1").value

if (s=="Small") {
event.value = n;
}
else if (s=="Medium") {
event.value = n*2;
}
else if (s=="Large") {
event.value = n*3;
}
else if (s=="Huge") {
event.value = n*4;
}
else if (s=="Tiny") {
event.value = n/2;
}

try67
Community Expert
Community Expert
July 5, 2021

You've never defined the variable "Strength1"... Also, you don't use the "s" variable after you've defined it in the first line, although that's not an error.

Inspiring
July 5, 2021

I am sorry, that first line is not used in this iteration of the code:

So it should just be:
if (getField ("size").value == "Small")
event.value = (Strength1);
else if (getField ("size").value == "Medium")
event.value = ((Strength1)*(2));
else if (getField ("size").value == "Large")
event.value = ((Strength1)*(3));

 

Strength1 is defined by input from the use of the PDF, and can range from 1 to 100

 

According to the Console, and there is a lot of reptitive responses, the error is:

TypeError: this.getfield is not a function
1:Field:Calculate
InvalidSetError: Set not possible, invalid or unknown.
Event.value:1:Field Throw:Calculate


ReferenceError: Strength1 is not defined
2:Field:Calculate

ReferenceError: Strength1 is not defined
3:Field:Calculate
InvalidSetError: Set not possible, invalid or unknown.
Event.value:1:Field Throw:Calculate

 

Yet, when I just do a Simplified Field Notation of:
((Strength1)*(2))
There is no error and it takes the value of Strength1 and multiplies it by the correct amount

 

 

 

Bernd Alheit
Community Expert
Community Expert
July 5, 2021

Javascript is case sensitive. Use this.getField, not this.getfield.

 

In the script you must use:

this.getField("Strength1").value

 

Bernd Alheit
Community Expert
Community Expert
July 5, 2021

What happens when you use it?

Have you checked the Javascript console for errors?

Where have you set Strength1?

Inspiring
July 5, 2021

Currently nothing happens. 

I have checked the console for errors and there does not appear to be any.  By console I am assuming you mean the custom calculation script input region.  When i check the code on https://jsfiddle.net/  and there does not seem to be any issues.

Strength 1 is set by user input and its a Numerical input.  It is on 1 page and the script is running on the next page.

 

Size DropDown Menu

I am learning how to do this.  I hope that I have given you what you requested/asked about.

 

 

Bernd Alheit
Community Expert
Community Expert
July 5, 2021

Open the console with ctrl-j or cmd-j