Highlighted

If/Then/Else Statments for javascript with drop down list and text field

New Here ,
Nov 13, 2020

Copy link to clipboard

Copied

Hi All,

I definitely over my head with this. This is my first time creating an interactive form and with javascript. I could leave my form as it is and it would be fine. But, I'm not happy with fine, because I know that it can be better. I searched the community posts and didn't see anything that was applicable. If I missed a relevant post, let me know and I'll check it out. I would appreciate any help you all can provide!

 

So here's what I am trying to work through. I am working on a Group Registration Form. On the form there is a table with multiple lines to enter registrants names. On each row, there is a drop down box, where you need to select member status:"Yes "or "No"

Kristin0D45_0-1605308933007.png

Based on the response to member status, I want to pull in information from two text fields- "memberprice" and "nonmemberprice" on the form.

Kristin0D45_1-1605309313437.png

For each row, in the price field, I need to figure out how to write the following statements.

If member status equals "Yes", than get member price value.

If member status equals "No", than get nonmember price value.

If member status equals "else" than nothing- leave it blank

 

I would be grateful for any help you all can provide!

TOPICS
PDF forms

Views

25

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

If/Then/Else Statments for javascript with drop down list and text field

New Here ,
Nov 13, 2020

Copy link to clipboard

Copied

Hi All,

I definitely over my head with this. This is my first time creating an interactive form and with javascript. I could leave my form as it is and it would be fine. But, I'm not happy with fine, because I know that it can be better. I searched the community posts and didn't see anything that was applicable. If I missed a relevant post, let me know and I'll check it out. I would appreciate any help you all can provide!

 

So here's what I am trying to work through. I am working on a Group Registration Form. On the form there is a table with multiple lines to enter registrants names. On each row, there is a drop down box, where you need to select member status:"Yes "or "No"

Kristin0D45_0-1605308933007.png

Based on the response to member status, I want to pull in information from two text fields- "memberprice" and "nonmemberprice" on the form.

Kristin0D45_1-1605309313437.png

For each row, in the price field, I need to figure out how to write the following statements.

If member status equals "Yes", than get member price value.

If member status equals "No", than get nonmember price value.

If member status equals "else" than nothing- leave it blank

 

I would be grateful for any help you all can provide!

TOPICS
PDF forms

Views

26

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
Nov 13, 2020 0
ls_rbls LATEST
Adobe Community Professional ,
Nov 13, 2020

Copy link to clipboard

Copied

See the correct answer by NesaNurani just posted today here:

 

https://community.adobe.com/t5/acrobat/auto-populate-question-please-help/m-p/11592923#M286024

 

For the script that I will share with you below, is very important that you confim if the listed Face value items of the dropdown boxes for "Yes" or "No" have no export values.

 

In any case, for this to work  you must establish  IF /ELSE conditional statements as the custom calculation script on each of the "PriceRow" fields.

 

For example, if the dropdown boxes do have export values, the script will look like this: 

 

 

// DECLARE VARIABLE AND GET THE FACE VALUE OF THE SELECTED ITEM OF THE DROPDOWN BOX

var f = this.getField("myDropdown");
var a = f.currentValueIndices;
var faceValue = f.getItemAt(a, false)


// ESTABLISH IF/ELSE CONDITIONAL STATEMENTS 

if (faceValue == "Yes") {

event.value = this.getField("Member Price").value; 

} else {

if (faceValue == "No") {

event.value = this.getField("NonMember Price").value; 
 
} else {

event.value ="";

 }
}

 

 

Now, for this script to work propperly, you must also select in the field properties options to commit selected value immediately, and also uncheck the option that allows users to enter custome text in this dropdown field.

 

If the "PriceRow" dropdown boxes don't have any export values then the script should be expressed like this:

 

var f = this.getField("myDropdown");

if (f.value == "Yes") {

event.value = this.getField("Member Price").value; 

} else {

if (f.value == "No") {

event.value = this.getField("NonMember Price").value; 
 
} else {

event.value ="";

 }
}

 

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...
Nov 13, 2020 0