These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

JavaSript for a Checkbox

Elya42
Registered: Mar 3 2009
Posts: 59

I am attempting to write a JavaScript for a checkbox and I am not sure of the script
This is what I wrote but I am fairly new to this and I guess I am just making mess of it. Please, if anyone can help, I would appreciate it so much.

var sum=("Yes6.1").value
sum=0-100;
If(sum<=69%);
event.rc=false;
{

app.alert("Action not Permitted - score is less than 70%")
}

Elaine M

My Product Information:
Acrobat Pro 9.1, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
So what exactly are you trying to do?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Elya42
Registered: Mar 3 2009
Posts: 59
when a user clicks on a checkbox - a score in a text box (within the document) needs to 70% or greater before the box is allowed to be checked.
I also need a app.alert to relay a message indicating why the box cannot be checked.

Can this even be done in Acrobat 9pro?

Elaine M

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, of course this can be done, in any version of Acrobat going back to Acrobat 3. But your job is to clearly and acurately describe the functionality you would like to implement. And you're not there yet.

But let me see if I get your description. You have a check box and and text box on a form. I assume the text box is calculated? If the value in the text box is below 0.7, then the check box will refuse to be set. And if the user attempts to click on the check box, then they get a popup alert. Is this correct?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi Elya42,

Yes, this and much more can be done with scripting. Since you are new to scripting there are some great tutorials in the Learning Center here. You should also get the official Adobe Acrobat JavaScript Documentation which lists all the Properties and Methods available and what can and can't be done with JavaScript in PDF forms and documents.

If you spend some time reading the Tutorials in the Learning Center here ( over 70 entries on Acrobat and LiveCycle Designer scripting topics) you will gain a wealth of scripting knowledge.

For basic training www.pdfscripting.com offers over 10 hours of training videos and covers all the basics from how to enter scripts, how to locate them, and even how to use the Acrobat JavaScript Reference ( which as I said is a must have is you are programming with JavaScript in PDF). It is not a free resource but is the most comprehensive one available on the subject.

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
Elya42
Registered: Mar 3 2009
Posts: 59
I purchased membership with pdf scripting and I have been going over the tutorials - still in a fog.

1. The first purpose of the checkbox is to select an item
2. But - the item may not be selected if a score in a text box is below 70% (The checkbox will not accept the action of a check mark)

Elaine M

Elya42
Registered: Mar 3 2009
Posts: 59
Thomp - yes you are correct in what I am attempting to accomplish.

Elaine M

grm311074
Registered: Apr 15 2009
Posts: 5
Hi everyone i need a help you see i was using previously the adobe acrobat version 6 professional for my work but now i have to shift to version pro 9. the problem is
In ver 6 pro i used to use link tool very extensively where i've to make links extensively to pages of another document which i was able to do easily, the approach was selecting the option "select a page of another document" using that i used to give the path and the page no without actually opening it but now in ver 7 onwards this feature has been modified and now for every link i have to open the page of a document that i have to link inorder to fulfill the requirement but this option is not solving my problem at all as i have already told that i've to make external links to pages of another document extensively, So can anyone help me out with a solution or a customised java script that can be updated in my acrobat and I will be able to work as easily as i was working in ver 6.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
grm311074, Start a new Thread. Your post has nothing to do with this topic.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Elya42,
I see that in a previous post you suggested using a validate script. This is the correct location for the functionality you want. It is inface very simple:
   var nSumVal = this.getField("Yes6.1").value;event.rc = (nSumVal >= 0.7);if(!event.rc)app.alert("Action not Permitted - score is less than 70%")

The code assumes that "Yes6.1" is the name of the field with the % value in it.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Elya42
Registered: Mar 3 2009
Posts: 59
I have double checked the script that I entered. It works, in that the message pops up but the checkbox still accepts the check, no matter what calculated value is in the related text box (Yes6.1)

Elaine M

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The important bit is that I wrote the script to be placed in the Validate event. You may have noticed that there isn't a UI for the Validate event in the properties dialog for the check box. If you want to add a validate script it has to be done programatically. You'll find the information to do this in the tutorials at pdfscripting.com, and I also wrote an aticle for this site on entering validation which I can't find at the moment.

But if you want to put this in a mouse up script, then do this
  var nSumVal = this.getField("Yes6.1").value;if(nSumVal <= 0.7){event.target.checkThisBox(0,false);app.alert("Action not Permitted - score is less than 70%")}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Elya42
Registered: Mar 3 2009
Posts: 59
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

It worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Elaine M