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

App alert based on checkbox value

Contributor ,
Jan 19, 2018 Jan 19, 2018

Experts,

The below script is partially working. I have a checkbox, "401k50", with a value of 0 or 1 (if checked). If checked, if in a different field User enters a number greater than 24500, the alert pops up and tells them the must enter a number between 0 and 24500. This works. So far so good. If the box, 401k50 is unchecked, and User enters a number greater than 18500, an alert box is supposed to tell User to enter a number between 0 and 18500. This is not working. Currently, if unchecked, user is able to enter any number he wishes. Here's my script:

//401k50 is a checkbox, value of 1 if checked, 0 if unchecked

var v1 = +getField("401k50").value;

//Checkbox is checked

if(v1 > 0){

     var v2 = +event.value;if (v2 > 24500) {

     app.alert("Since you are over 50 you are eligible for a catch-up 401(k) contribution. Please enter a number between 0 and 24,500.",3);

     event.rc=false;

}

// Checkbox is unchecked

else if(v1 < 1){

    var v2 = +event.value;if (v2 > 18500) {

    app.alert("Please enter a number between 0 and 18,500.",3);

    event.rc=false;

}

}

}

Any help appreciated!

TOPICS
Acrobat SDK and JavaScript , Windows
1.4K
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

Community Expert , Jan 19, 2018 Jan 19, 2018

Is this a validation script on the field where the value is being entered?  It should be.

So, checkbox values are not 0 and 1.  The value of a checkbox is either the export value or "Off"

Event.value can be used by itself, there is no reason to assign it to V2.

var v1 = getField("401k50").value;

event.rc = true;

if(v1 == "Yes")

{

    if(event.value >24500)

    {

          app.alert("Since you are over 50 you are eligible for a catch-up 401(k) contribution. Please enter a number between 0 and 24,500.",3);

...
Translate
Community Expert ,
Jan 19, 2018 Jan 19, 2018

Is this a validation script on the field where the value is being entered?  It should be.

So, checkbox values are not 0 and 1.  The value of a checkbox is either the export value or "Off"

Event.value can be used by itself, there is no reason to assign it to V2.

var v1 = getField("401k50").value;

event.rc = true;

if(v1 == "Yes")

{

    if(event.value >24500)

    {

          app.alert("Since you are over 50 you are eligible for a catch-up 401(k) contribution. Please enter a number between 0 and 24,500.",3);

          event.rc = false;

    }

}

else

{

    if(event.value >18500)

    {

          app.alert("Please enter a number between 0 and 18,500.",3);

          event.rc = false;

    }

}

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
Contributor ,
Jan 19, 2018 Jan 19, 2018
LATEST

Thom,

Thanks for the quick response! Yes, this is validation script. Your script works perfect!

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