Copy link to clipboard
Copied
Hi,
I have a form with a couple of fields. One text field is named "Total" and the other field is named "DropFreq". I would like a to have a pop-up alert the user when the "Total / DropFreq = less than 1000" to say somethine along the lines of "Please try to have more than 1000 per drop." The user can still click the alert box away and "save" the form even if it's less than 1000. It's just a friendly reminder/suggestion. Thank you for your help in advance!
A simple way to do this is to add a hidden field that performs the division and then checks the value. Add this calculation script to the hidden field.
var nDropFreq = this.getField("DropFreq").value;
// only do calculation if DropFreq is a number that is not 0
if(!isNaN(nDropFreq) && (Number(nDropFreq) != 0))
{
if(this.getField("Total").value/nDropFreq < 1000)
app.alert("Please try to have more than 1000 per drop.",1,0);
}
Copy link to clipboard
Copied
A simple way to do this is to add a hidden field that performs the division and then checks the value. Add this calculation script to the hidden field.
var nDropFreq = this.getField("DropFreq").value;
// only do calculation if DropFreq is a number that is not 0
if(!isNaN(nDropFreq) && (Number(nDropFreq) != 0))
{
if(this.getField("Total").value/nDropFreq < 1000)
app.alert("Please try to have more than 1000 per drop.",1,0);
}
Copy link to clipboard
Copied
Thom, thank you! This is awesome. Is there a way to remove the "Warning JavaScript Window - " from the title? I was able to add my own title, but it just adds it to the right of "Warning JavaScript Window - ". This is amazing. Thank you for your help.
Copy link to clipboard
Copied
The answer is yes and no. Acrobat adds warnings to popup dialogs to prevent spoofing when code is executed from non-privileged locations. Making the code privileged is probably not practical for your form. But you can read about it here if you are interested:
https://www.pdfscripting.com/public/Trust-and-Privilege-in-Acrobat-Scripts.cfm
There is another technique that works for forms, which is to use a button to display your message. The idea is to make the button look a bit like a popup alert using the appearance settings and possibly a background image. Instead of calling app.alert in the code, just make the button visible. Of course it would be pre-placed over the area of interest. Then use the mouse up on the button to hide it (no code is necessary for this).
Here's an article on hiding and showing fields:
https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm
Copy link to clipboard
Copied
Thom, thanks again. Amazing.