Skip to main content
August 25, 2016
Question

how to add change event to check box in pdf using javascript

  • August 25, 2016
  • 3 replies
  • 5598 views

Hi,

Can any one help me on adding change event to the check box?

1. If the check box is marked it will bring us to new page.  If it is not marked needs to remain in same page.

2.  how to add events to the fields in the adobe reader through javascript.

Thank you

Ariv

This topic has been closed for replies.

3 replies

August 29, 2016

I got the solution to call more than one function.

try67
Community Expert
Community Expert
August 25, 2016

A check-box field doesn't have a "change" event, like a text box, for example. However, you can utilize other event to achieve the same thing. For example, the MouseUp event. You can use event.target.value to access the current value of the field in that event, and then proceed with the rest of your logic.

August 25, 2016

I tried

chkbox = app.trustedFunction(function()

{

app.beginpriv();

var aRCBRect = [18,50,80,100]

var f=this.addField("myCheck", "checkbox",1,aRCBRect);

f.borderStyle = border.b;

f.exportValues=["Yes"];

f.lineWidth = 1;

f.strokeColor=color.black;

f.style=style.ch

f.textSize=35;

f.value="Off"

f.setAction("MouseUp", validate(f)");

function validate(x)

{

if(x.value=="Yes")

{

this.pageNum++;

}

}

app.endPriv();

});

app.addToolButton({

cName:"chkbox",

cExec:"chkbox()"

cTooltext: "Check Box"});

it is working fine in document level script with out toolbutton. 

While trying to add this script in folder level using toolbutton.  it is not working.  I am getting "validate is not defined 1: Field:Mouse Up Up" error.  here validate function i have defined.  can u help on this.

can u tell me what is the use of the line "f.exportValues=["Yes"];" in the script.

Thank you

Ariv

Bernd Alheit
Community Expert
Community Expert
August 25, 2016

You defines the function "validate" inside of function "chkbox". Put the definition at top-level.

Inspiring
August 25, 2016

You can't add any actions with Reader. Do you have access to Acrobat?

August 25, 2016

Yes I am having Adobe Acrobat Pro DC.

Inspiring
August 25, 2016

Is there a reason you don't want to use a button? It's more flexible in what actions can be used with it and a much more standard means of navigation than a check box.