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

Javascript not working

Engaged ,
May 09, 2017 May 09, 2017

Hello everyone,

I created a form with some JavaScript functionality. It works in Adobe Acrobat DC, but it doesn't work in Reader on our company website.

Is there a reason for this?

Thanks,

Jake

TOPICS
Acrobat SDK and JavaScript , Windows
15.4K
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

correct answers 1 Correct answer

Community Expert , May 12, 2017 May 12, 2017

I’m going to guess that the marketing department opened it in Preview on OSX and then saved the file… or inadvertently saved it after some minor change. Preview... without warning... removes scripts from PDF form fields every chance it gets.

J-

Translate
Community Expert ,
May 09, 2017 May 09, 2017

Acrobat Reader doesn't support all JavaScript features.

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 ,
May 09, 2017 May 09, 2017

What kind of "functionality"?

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
Engaged ,
May 11, 2017 May 11, 2017

All I am doing is adding JavaScript to form fields:

function check () {

//Foot Options is the name of the radio button group

//Javelin is the name of the radio button

//If the selected radio button isn't called Javelin

if(this.getField("Foot Options").value != "Javelin"){

//Don't allow both to be selected

this.resetForm("Top Housing");

}

}

check();

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 ,
May 11, 2017 May 11, 2017

resetForm takes either nothing or an array as a parameter. See the brackets around your field name below.

function check () {

//Foot Options is the name of the radio button group

//Javelin is the name of the radio button

//If the selected radio button isn't called Javelin

if(this.getField("Foot Options").value != "Javelin"){

//Don't allow both to be selected

this.resetForm(["Top Housing"]);

}

}

check();

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 ,
May 11, 2017 May 11, 2017

You're right, but resetForm will work if you specify only a single field's name, even if it's not in an array.

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 ,
May 11, 2017 May 11, 2017

Did you open the form in Acrobat Reader?

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
Engaged ,
May 12, 2017 May 12, 2017

The form has been put on a website as a link. It seems to be opening in the browser instead of in Acrobat Reader. Could this be the problem?

Edit: Adobe Acrobat Reader is Enabled in the browser. So even though it opens from the browser, it looks as though the PDF opens inside Reader.

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 ,
May 12, 2017 May 12, 2017

Are you sure? What browser are you using?

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
Engaged ,
May 12, 2017 May 12, 2017

Yes I've just checked on Chrome and Explorer.

However, I have just found out that the JavaScript actions are no longer on the form fields.

Is there any way this could have happened, other than someone doing it manually?

My original PDF has the JavaScript action. I sent it to our Marketing department to put on the website and now the JavaScript actions aren't there.

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 ,
May 12, 2017 May 12, 2017

Chrome uses an internal PDF plugin, not the Adobe one.

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
Engaged ,
May 12, 2017 May 12, 2017

Would this remove JavaScript from Form Fields?

All the fields are still named the same as when I created them.

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 ,
May 12, 2017 May 12, 2017

No, but it will not execute them correctly, most likely.

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 ,
May 12, 2017 May 12, 2017

I’m going to guess that the marketing department opened it in Preview on OSX and then saved the file… or inadvertently saved it after some minor change. Preview... without warning... removes scripts from PDF form fields every chance it gets.

J-

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
Engaged ,
May 15, 2017 May 15, 2017

This sounds like the most likely reason Joel, thank you

I wasn't aware that this happens in Preview on OSX.

Thanks everyone for your comments.

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
New Here ,
May 18, 2017 May 18, 2017

Thanks Joel. Is there anything that we can do to avoid this?

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 ,
May 18, 2017 May 18, 2017

Put a sign over the coffee machine that reads "Preview is poison to PDF"?

Seriously though... simply installing Adobe Reader will cause it to take over the file type association so the default won't be to open in Preview. If that's not going to work for you a bit of training might help.

One thing I've been considering is to create a little tool that will pop up an alert when a PDF is opened that contains form fields and has been saved by Preview basically telling people that the form data is probably corrupted.

Any thoughts on that?

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
New Here ,
May 18, 2017 May 18, 2017

Love the sign idea, but won't work since my pdf files don't go to a company they are for people literally all over the world.

Some may have Reader installed (most do), however now that browsers make it "easy" to view pdf files, many just open in the browser and go from there.

Creating that little tool sounds like a great idea! Will that tool work being just attached to the file itself (basically "server side" where the file is stored) or would it only work it could be installed on the client machine?

It's just annoying that you get a great piece of javascript to do these awesome calculations, but in certain instances they don't work because of how people are viewing/utilizing the pdf form. There has to be some way around this..like a setting when developing the form to not let them preview or something (basically have to download and use Adobe Reader and not the browser or previews... I'm sure that's asking too much...

Open to any and all ideas though...thanks, Joel!

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 ,
May 19, 2017 May 19, 2017

nicolek13929741  wrote

It's just annoying that you get a great piece of javascript to do these awesome calculations, but in certain instances they don't work because of how people are viewing/utilizing the pdf form. There has to be some way around this..like a setting when developing the form to not let them preview or something (basically have to download and use Adobe Reader and not the browser or previews... I'm sure that's asking too much...

Actually... it's not asking too much. Actually it's quite simple. You just create a "warning" and put it on a layer. The you add a JavaScript to the document that, if it's able to run, hides the layer. This limits the viewers that can be used without showing the layer to Adobe's and just a few others. You can completely restrict it to just Adobe products using the same technique but different conditions in the "if" statement.

You can see an example here...

http://www.adobe.com/showcase/casestudies/mcgladreydyn/casestudy.pdf

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
New Here ,
May 23, 2017 May 23, 2017

Hey Joel - that's a great example!!! Where do I go to learn how to do this???

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 ,
May 23, 2017 May 23, 2017

Do you have a TARDIS? I learned it over the course of 20 years.

Though a good place to start is pdfscripting.com

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
New Here ,
May 23, 2017 May 23, 2017
LATEST

LOL - my TARDIS has been on the fritz.

Thanks for the link - I'll see if I can figure it out. Unless you're for hire and could teach this?

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