Search code examples
javascriptacrobat

Re-checking a checkbox in Acrobat


I have some basic error-checking on my Acrobat form. In one bit of logic, a checkbox can be checked, which then allows the user to fill in information on a second person by setting all the fields to [.visible].

When the user un-checks the box, an alert informs them that by continuing, they will cause all secondary personal information to be deleted, and do they want to continue. If they click the "OK" button, then it proceeds to clear the form data and set all the fields to [.hidden] again. If they click "Cancel", then it is supposed to interrupt the clearing of the fields (which works), and force the checkbox to be re-selected, appearing as if it had never been cleared.

This is the part that isn't working. The checkbox, when "On", gets checks (by accident?), the alert asks for confirmation. If "Cancel" is chosen presumably because they don't want to clear the information, the checkbox remains unchecked, even though the alert cancelled the clear action. How do I make the checkbox re-check itself if the user clicks the "Cancel" button on the alert?

This is my code...

if (getField("chkHasCap").value == "Off") {
if (app.alert("Clicking this will reset all Co-Applicant information.  Are you sure you want to proceed?", 3, 1) == 1) {
fClearCoApp();
app.alert("Co-applicant information has been reset...", 3);
}

else {
    app.alert("Co-Applicant information has NOT been reset...", 3);
    getField("chkHasCap").value = "On";
    calculateNow();
    getField("fldCreditScore_Cap").readonly = false;
    getField("fldCreditScore_Cap").setFocus();
}
}

Solution

  • Unless you've changed it, the default value of a checked box will be "Yes" rather than "On"... I know... it's crazy-making but that's what Acrobat does. You should just need to change the second line after your else statement.

    getField("chkHasCap").value = "Yes";