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

Need help with javascript and if/then/else statements

New Here ,
Oct 19, 2017 Oct 19, 2017

Hello everyone!   I have searched this forum for days and tried many things but cannot find a workable solution to my problem.  My javascripting skills are novice at best.

I have created a numerical free text box "NumberValue" and a dropdown menu "TextChoices" with 5 text choices (ie Text1, Text2, Text3, Text4, Text5).  IF the user selects Text1 AND the previous numerical box "NumberValue" is >12 THEN make the "NumberValue" = 12.  IF the user selects Text1 AND the "NumberValue" is <12 THEN make "NumberValue" = the users input.  IF the user selects any other text choice THEN "NumberValue" = the users input.

Any advice other than closing the program and walking away?

TOPICS
Acrobat SDK and JavaScript
477
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

LEGEND , Oct 19, 2017 Oct 19, 2017

You could use a custom Validate script for the NumberValue field, something like this:

// Custom Validate script of a numeric text field

(function () {

     // Get the value of the TextChoices field, as a string

     var sTextChoices = getField("TextChoices").valueAsString;

     // Alter this field's value if necessary

     if (+event.value > 12 && sTextChoices === "Text1") {

         event.value = 12;

     }

})();

Translate
LEGEND ,
Oct 19, 2017 Oct 19, 2017

You could use a custom Validate script for the NumberValue field, something like this:

// Custom Validate script of a numeric text field

(function () {

     // Get the value of the TextChoices field, as a string

     var sTextChoices = getField("TextChoices").valueAsString;

     // Alter this field's value if necessary

     if (+event.value > 12 && sTextChoices === "Text1") {

         event.value = 12;

     }

})();

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 ,
Oct 20, 2017 Oct 20, 2017
LATEST

George,

YOU, sir, are amazing!  Thank you!  Your script opens up so many options.  One followup question though.  I've noticed upon testing that if I were to populate the numeric text field first THEN select the proper text choice from the dropdown, the numeric text field still maintains the user entered value.  The script works great if the text choice was selected first then the numeric text field was populated.

Is there an option to have the numeric field update if the appropriate dropdown text choice is chosen after the numeric text field population?

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