Copy link to clipboard
Copied
So, I keep putting this script into a checkbox:
var checkbox = this.getField("Check Enclosed"); var fields = ["Signature", "Billing Address", "Name on Card", "CVV", "Exp Date", "Name", "Card"]; function setRequiredFields() { for (var i = 0; i < fields.length; i++) { var field = this.getField(fields[i]); field.required = checkbox.value === "Off"; } } checkbox.setAction("MouseUp", "setRequiredFields();"); setRequiredFields();
And it works fine, but when I save and open the document again it replaces the script with just
setRequiredFields();
Anyone know why this might be happening?
Copy link to clipboard
Copied
Because that's what you're telling it to do in the penultimate line of your code... The first part of the code (until the end of the function) seems like it should be a doc-level script, although defining the check-box variable outside the function doesn't make much sense.
The line before last should be executed only once, from the JS Console.
The last line should be removed entirely.
Copy link to clipboard
Copied
Because that's what you're telling it to do in the penultimate line of your code... The first part of the code (until the end of the function) seems like it should be a doc-level script, although defining the check-box variable outside the function doesn't make much sense.
The line before last should be executed only once, from the JS Console.
The last line should be removed entirely.
Copy link to clipboard
Copied
The setAction field method writes the action script setRequiredFields(); You shouldn't be using this method as part of a field script. It is more of an automation tool to write scripts or formats into fields.
Copy link to clipboard
Copied
The reason is this line:
checkbox.setAction("MouseUp", "setRequiredFields();");

