I am absolutely newbie in Javascript.
I have a form in PDF and want to add a Javascript action to it. Let's say I want an alert es up when someone clicks on a check box.
Here is what I do:
1-first open the form in Acrobat Pro -> Tools-> Form -> edit:
2-then click on a checkbox-> Properties
and select action -> Run Java Script
and added this code:
<SCRIPT language = "JavaScript">
alert("Wele to the script tag test page.")
</SCRIPT>
After saving , nothing happens when I click on this checkbox. I am not sure if my Java code is wrong or I am missing something in the Acrobat Pro or something ?!
I am absolutely newbie in Javascript.
I have a form in PDF and want to add a Javascript action to it. Let's say I want an alert es up when someone clicks on a check box.
Here is what I do:
1-first open the form in Acrobat Pro -> Tools-> Form -> edit:
2-then click on a checkbox-> Properties
and select action -> Run Java Script
and added this code:
<SCRIPT language = "JavaScript">
alert("Wele to the script tag test page.")
</SCRIPT>
After saving , nothing happens when I click on this checkbox. I am not sure if my Java code is wrong or I am missing something in the Acrobat Pro or something ?!
Share Improve this question edited Feb 21, 2017 at 6:45 Trevor 1,4443 gold badges16 silver badges33 bronze badges asked Oct 29, 2014 at 17:45 AugAug 5991 gold badge9 silver badges22 bronze badges 1-
You don't need
<script>
tag, I don't thought that an alert works in Adobe Acrobat. Try to refer you to Javascript API doc – Alex L. Commented Oct 29, 2014 at 17:55
1 Answer
Reset to default 5Wele to scripting PDFs.
First and foremost, Java and JavaScript are not the same. All they have in mon are three characters.
Second, JavaScript is much more than what they tell you it is when using it in webbrowsers. JavaScript consists of the Core and the application-specific extensions. Webbrowser JavaScript consists of the Core and the webbrowser-specific extensions. This is shown best in Flanagan's JavaScript, the Defnitve Guide, published by O'Reilly.
So, Acrobat JavaScript consists of the Core and the Acrobat-specific extensions. Those are documented in the Acrobat JavaScript documentation, which is part of the Acrobat SDK, downloadable from the Adobe website.
Then, there is the object model playing another role. This is also described in the Acrobat JavaScript documentation.
I insist on this documentation, because that's what you need to have at hand, and you should have at least quickly read through the Guide and glanced at the Reference (which does have code samples).
Then you will see that the code you tried — which is syntactically correct JavaScript — simply does not work in Acrobat.
Actually, it seems that you wanted a checkbox to pop up an alert saying "Hello World" when being checked. Actually, you got to the correct event to use; using the MouseUp event for clicking is how the document object model in PDF forms works.
One possibility to make appear the alert box would actually look like this:
if (event.target.value != "Off") {
app.alert("Hello World") ;
}
and that would do it…
There would be other ways do do it when you are using another field to contain the code.