Skip to main content
Inspiring
January 19, 2018
Answered

App alert based on checkbox value

  • January 19, 2018
  • 1 reply
  • 1477 views

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!

This topic has been closed for replies.
Correct answer Thom Parker

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;

    }

}

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
rsbisaAuthor
Inspiring
January 19, 2018

Thom,

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