Copy link to clipboard
Copied
On a mac using Acrobat Pro. I'm working on a pdf form with a fair amount of embedded javascript and I'm stuck on something that seems like it should be straightforward, but my script knowledge is just too basic.
There are two fields which need to be unique. If the same number goes in both fields I'd like a warning to flash up and to prevent the pdf from being submitted. I tried adding a validation script to the individual fields. Field A:
if (this.getField("FieldB").value==event.value({
app alert("Warning");
}
I've tried variants on this defining the variable of fields A and B and doing if/else but I'm just not managing to get it to work.
The two fields which need to be unique have a custom format as they are number fields which allow leading zeros, not sure if this is complicating matters? They're both required fields.
Anyone able to point me in the right direction?
Copy link to clipboard
Copied
Your custom validation script look good, but it has a couple of syntax errors.
if (this.getField("FieldB").value==event.value){
app.alert("Warning");
}
See if this works.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Your custom validation script look good, but it has a couple of syntax errors.
if (this.getField("FieldB").value==event.value){
app.alert("Warning");
}
See if this works.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks so much for response - the field 'accepts' your code but I'm not getting a warning pop-up when the fields are identical. I've added it to the field as a Validation script - is that correct?
Copy link to clipboard
Copied
Yes, it needs to be a validation script. There's nothing obvious, so you'll need to do some debug now. Start by looking in the console window for any reported errors. Then add a console.println statement into the validation script so you can see exactly what the values are that are being used.
BTW: the number formatting for the fields has no affect on the script, or the real field value. But it could be making it look as if the fields are the same, when they are not. For testing this script I would suggest removing the format so you can see the real values.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I'm not sure what I did - nothing came up in debugger so I removed the custom format script. Warning worked. Put the custom format script back in and it's all still working! Which is the main thing. Thank you so much I've been going daft trying to figure this out!
Copy link to clipboard
Copied
To prevent the file from being submitted you will need to submit it using a script (not the built-in Submit a Form command), and add this logic before the command to send the file.

