Skip to main content
Inspiring
Jan 19, 2018 7:56 PM UTC
Answered

App alert based on checkbox value

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 is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Jan 19, 2018 8:17 PM UTC

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

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Jan 19, 2018 8:17 PM UTC

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;

    }

}

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
rsbisaAuthor
Inspiring
Jan 19, 2018 9:01 PM UTC

Thom,

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

Translate