Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guest
Aug 24, 2016 Aug 24, 2016

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

TOPICS
Acrobat SDK and JavaScript
5.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2016 Aug 24, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 24, 2016 Aug 24, 2016

Yes I am having Adobe Acrobat Pro DC.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 25, 2016 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2016 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2016 Aug 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2016 Aug 25, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2016 Aug 25, 2016

Hi,

two functions i have used. one is 'chkbox' function that is called by toolbutton.  And another function is 'validate' that is inside the 'chkbox' function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2016 Aug 25, 2016

Couple of issues. First of all, this line is incorrect:

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

You're missing a double-quote before validate, and also at the moment the field is clicked, "f" is not a defined variable.

Instead, use this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2016 Aug 25, 2016

I have tried.  Still it is showing error "validate is not defined 1: AcroForm:myCheck: Annot4:Mouse Up:Action1".

I want check box to respond on my mouse click.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2016 Aug 25, 2016

Forget about the function. Just use this:

f.setAction("MouseUp", "if (event.target.value!=\"Off\") this.pageNum++;");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2016 Aug 25, 2016

very useful. It is working now. Thank you very much.

Ariv

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 28, 2016 Aug 28, 2016

Hi,

I am having another doubt in this can u able to clarify this.

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)

{

app.alert("Success");

}

app.endPriv();

});

app.addToolButton({

cName:"chkbox",

cExec:"chkbox()"

cTooltext: "Check Box"});

above is working fine.  If I wanted to call another function at MouseUp event what should i need to do.  How I can call multiple functions at mouse up event.

Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2016 Aug 29, 2016
LATEST

I got the solution to call more than one function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines