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

Need help - app.Alert when Checkbox selected but not when unselected

Michael Frommer
Registered: Apr 3 2009
Posts: 80
Answered

Would someone tell me if the following script will do what I want and what syntax error I have.

I want an alert message (with a checkbox) to pop up if a certain checkbox on my doc (used like a radio) is On (with export value = "member"). The problem I've had in the past is that when the doc's checkbox is unchecked, the alert pops up again. I only want the alert to pop up on the initial checkbox selection but not to pop up (for a 2nd time) upon the mouse up action of unchecking it (turning it 'off').

I thought it should be placed on the mouse up action.
Using Acro Pro 8

{
var oCK = {bAfterValue:false);
if ((this.getField("Reg.Type").isBoxChecked(1)) && (this.getField("Reg.Type").value) == "member");
app.alert ({cMsg: "my message.\n\n" + "my message.", nIcon3, cTitle: "REGISTRATION ALERT", oCheckbox:oCk});
hideWarning1 = oCk.cAfterValue;
}

I get a synatax error that I am missing a ) after the last line

My Product Information:
Acrobat Pro 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You have 3 syntax errors and some unnecessary code.

If "Reg.Type" is the name of the checkbox this code is attached to, then the "getField()" call is unnecessary, use "event.target" instead.

Also, there is no need to test for the export value and check value, these are equivalant.

I take it there is more than one check box? Hence the "1" instance index in the call to "isBoxChecked()"

Syntax errors:
The alert check object ends with a ")" instead of a "}". All dimited blocks have to begin and end with the same delimiter, no matter what kind of element they are.

The outside curly braces "{}" are misplaced. The opening brace "{" needs to be placed after the "if"

There is a semicolon following the "if", delete it.

The correct code should look like this:
var oCK = {bAfterValue:false};if (event.target.isBoxChecked(1)){app.alert ({cMsg: "my message.\n\n" + "my message.", nIcon3, cTitle: "REGISTRATION ALERT", oCheckbox:oCk});hideWarning1 = oCk.cAfterValue;}

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

Michael Frommer
Registered: Apr 3 2009
Posts: 80
thomp wrote:
You have 3 syntax errors and some unnecessary code.If "Reg.Type" is the name of the checkbox this code is attached to, then the "getField()" call is unnecessary, use "event.target" instead.
Yes it is.

thomp wrote:
Also, there is no need to test for the export value and check value, these are equivalant.
I still a noob at this. Like I said in my OP, I thought I would need the double test to stop the alert from popping up when the checkbox is unselected.

In the past, I've tried to have this happen but I only tested for the export value. I couldn't stop the alert upon the 2nd mouse click (unchecking action). This is the first time I'm using the "isBoxChecked" syntax.

Thanks for the advice.

thomp wrote:
I take it there is more than one check box? Hence the "1" instance index in the call to "isBoxChecked()"
Actually, I thought the "1" meant 'yes', checkbox is 'on'.

There are, in fact, 10 sets of checkboxes ("Reg.Type.1; Reg.Type.2; etc.). (20 checkboxes in total). I am using the checkbox instead of the radiobutton, each set with different export values) to allow for the un-selection within any given set, so that both checkboxes can remain unselected within a given set. I have found that that is not the behavior of the actual radio button field.

thomp wrote:
Syntax errors:
The alert check object ends with a ")" instead of a "}". All dimited blocks have to begin and end with the same delimiter, no matter what kind of element they are.

The outside curly braces "{}" are misplaced. The opening brace "{" needs to be placed after the "if"

There is a semicolon following the "if", delete it.

The correct code should look like this:
var oCK = {bAfterValue:false};if (event.target.isBoxChecked(1)){app.alert ({cMsg: "my message.\n\n" + "my message.", nIcon3, cTitle: "REGISTRATION ALERT", oCheckbox:oCk});hideWarning1 = oCk.cAfterValue;}
I was trying to use this code as a document script and call to it from 1 checkbox out of each set. (I then want to use a different alert message if the other checkbox in each set is selected.)

The exact same 2 messages is being used for each group of checkboxes. I just thought it would be easier to call to a document script from each checkbox. What are your thoughts? I appreciate all the help and education you are able to provide.

When I do use it as a script from the checkbox, still get syntax errors after I copied your corrections:
"missing: after property id 4: at line 5"
and it highlights:
hideWarning1 = oCk.cAfterValue;
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The problem is the call to the app.alert. The "nIcon" property is missing a ":" between the property name and the value. Should be
app.alert ({cMsg: "my message.\n\n" + "my message.", nIcon:3, cTitle: "REGISTRATION ALERT", oCheckbox:oCk});
Also, it is a bad idea to end a field name with ".#", i.e. "Reg.Type.1", "Reg.Type.2". These dot numbers are also used to reference specific widget instances so it can be confusing.

If there is more than one check box named "Reg.Type.#" then all of these check boxes act as a radio button group. Is this what you are trying to do? The number in "isBoxChecked()" refers to the Widget instance id. To make things easier, maybe you should be checking the export value rather than trying to ID a specific widget instance. So change your "if" statement to:

if(event.target.value == "member")
{
...
}

If this code will be called from more than one place, then YES, it's a great idea to make it a document level function. But, then you need a function definition in the document level script:

function CheckMyCheck()
{
... Place code here ...
}

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

Michael Frommer
Registered: Apr 3 2009
Posts: 80
thomp wrote:
The problem is the call to the app.alert. The "nIcon" property is missing a ":" between the property name and the value. Should be
app.alert ({cMsg: "my message.\n\n" + "my message.", nIcon:3, cTitle: "REGISTRATION ALERT", oCheckbox:oCk});
That took care of the syntax error; thanks for catching that. I got the alert to pop up, calling to it on the doc level script.

[b]BUT, the argument for the oCheckbox "Do not show this message again" is not working.[/b] Checking it does not stop the alert from popping up. [u][b]What's missing[/u][/b]?

Let me clarify the senarios. There are 2:

[u]Senario 1[/u]:
checkbox "Reg.Type.1" value = "member" - msg alert runs
user checks "do not show again"
checkbox "Reg.Type.2" value = "member" - msg alert [b]SHOULD NOT RUN, but it still does[/b] with current code

I imagine it is because I am calling the script as if for the first time from Reg.Type.2? Is there any code I can add to prevent this from happenning?

[u]Senario 2[/u]:
checkbox "Reg.Type.1" value = "member" - msg alert runs
user checks "do not show again"
User selects other radio/checkbox "Reg.Type.1" value = 'non-member"
User changes, again, back to original selection: checkbox "Reg.Type.1" value = "member" - msg alert [b]SHOULD NOT RUN, but it still does[/b]

thomp wrote:
If there is more than one check box named "Reg.Type.#" then all of these check boxes act as a radio button group. Is this what you are trying to do?
Yes. There are two named "Reg.Type.1", there are two named "Reg.Type.2", etc.

thomp wrote:
The number in "isBoxChecked()" refers to the Widget instance id.
I removed it "(1)". I had taken a sample script from one that uses an array. That makes sense now. Since I am still very, very new at this; I havent fully comprehended the idea of Widgets.

thomp wrote:
To make things easier, maybe you should be checking the export value rather than trying to ID a specific widget instance. So change your "if" statement to:if(event.target.value == "member")
{
...
}
When I used (event.target.isBoxChecked) by itself the msg alert worked, but the alert reappeared when unchecking (not selecting the 'other radio/checkbox). This is the problem I mention in my OP. So I added back the double test using && (event.target.value == "member") that solved that particular issue.I would be most greatfull if you can continue to assist with the remaining issue: that the 'Dont show this again' doesnt work.
Michael Frommer
Registered: Apr 3 2009
Posts: 80
I figured it out. Kept looking at the [url=http://www.acrobatusers.com/tutorials/2006/popup_windows_part1]tutorial[/url] and finally figured out what was missing; added a third test to the if argument:

if ((event.target.isBoxChecked) && (event.target.value == "member") [color=red]&& !this.hideWarning1[/color])Now my script works as planned.
fedrikwhite
Registered: Aug 19 2009
Posts: 3
Thanks, I appreciate all help and advice! I will keep you posted. It seems like a very difficult process but I'll keep after it.