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

Javascript for form

New Here ,
Jan 05, 2018 Jan 05, 2018

Would someone be able to help me write a java script for the following:

I have a form that has two columns:

1st column is Meals

where they input the $ Amount

2nd column is a dropdown menu where they select one of the following.

B -  has a maximum of $10.00

L - has a maximum of $15.00

D - has a maximum of $25.00

What I would like the script to do…if possible.

Under the 1st Column when they fill in the $ amount and then select from the dropdown menu (B, L or D) if the dollar amount exceeds the maximum it will automatically change the amount in the 1st column (Meals $ Amount) to the maximum amount.

TOPICS
Acrobat SDK and JavaScript , Windows
280
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 05, 2018 Jan 05, 2018
LATEST

To do this you'll need to change the export value on the dropdown items to match the dollar amounts. so for the first one the export value would be 10.

Then in the "Format" tab on the Field Properties, Select "Custom" formatting, and then add this code to the KeyStroke script.

if(!event.willCommit)

{

     if(this.getField("Test").value > event.changeEx)

           this.getField("Test").value = event.changeEx;

}

There is a couple of issues with this code.

1. It only handles the case where the user selects from the dropdown. It does not prevent the user from changing the value at a later time.

2. You'll need to enter this code into every dropdown in the column. This is not only tedius, it is error prone. Especially if you have to make changes, which you will. A better strategy is to create this code as a document level function, then call it from the field event.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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