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

Javascript not working in PDF

New Here ,
Aug 27, 2020 Aug 27, 2020

I have a fillable PDF with a dropdown. I followed advice I saw on here and I have a text box that each selection is saved to. But the dropbox always shows the last selection rather than resetting. I have tried many things and cannot figure it out. I used actions for mouse enter and reset a field but only the one field.

I used run Javascript and entered a line to reset. I tried mouse exit, up, down, onfocus annd blur just for the heck of it.

An analyst from my department spend a couple hours on it too and he said it is set right but it is not doing what it is told.

The closest it gets is it resets when the mouse gets near it afterwards. Like it works like a hover not a click.

I also wondered if I could have each selection on its own line in my testbox. Currently it is separated by a comma and wraps unevenly at the end of the line.

 

I have to turn this over to an end user and I hate to give it so messy.

 

Thanks much!

TOPICS
Acrobat SDK and JavaScript
2.2K
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 27, 2020 Aug 27, 2020

1. If you want us to make suggestions about what is wrong with code, it helps to share it! Please share your exact code for people to try, because the problem is often not where you think it is.

2. Please confirm you have checked the JavaScript console and there are no error messages there. Or if there are messages please share 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
New Here ,
Aug 27, 2020 Aug 27, 2020

Thanks I will. This is my first attempt for help on here. Can I upload the file?

 

This is under all Javascripts:

/

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<Document-Level>
//<ACRO_source>dropdown</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:dropdown ***********/
function UpdateTextField(doc, fieldName, newValue)
{
var ar = [];
// Get the values currently stored in the text field and
// convert them to an array
var v = doc.getField(fieldName).value;
if (v.length > 0) {
var ar = v.split(",");
}
// Do we already have newValue in the array?
var foundIt = -1;
for (var i=0; i<ar.length; i++) {
if (ar[i] == newValue) {
foundIt = i;
break;
}
}
if (foundIt != -1) {
// remove the item
ar.splice(i, 1);
}
else { // add the item at the end
ar.push(newValue);
}
// If we have more than four elements,
// remove the oldest one
while (ar.length > 4) {
ar.shift();
}
// conver the array to a string
this.getField(fieldName).value = ar.join();
}
//</ACRO_script>
//</Document-Level>

//<AcroForm>
//<ACRO_source>ddtype:Validate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ddtype:Validate ***********/
UpdateTextField(this, "Text1", event.value);
//</ACRO_script>
//</AcroForm>

 

/*********** belongs to: AcroForm:ddtype:Validate ***********/
UpdateTextField(this, "Text1", event.value);
//</ACRO_script>
//</AcroForm>

 

This is in the Action tab of the DD:

I have selected Mouse Enter as my trigger and run a JavaScript as Action.

this.resetForm(["ddtype"]);

 

This is in Validate: 

I have also checked Run a custom validation script.

UpdateTextField(this, "Text1", event.value);

 

Debugger is blank.

 

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 27, 2020 Aug 27, 2020

Remove var from this line: 

var ar = v.split(",");

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 27, 2020 Aug 27, 2020
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 ,
Aug 27, 2020 Aug 27, 2020

Sorry, yes. Does it go in here: where the comma is"
ar = v.split(",");

[Private info removed. -Mod.]

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 27, 2020 Aug 27, 2020

Use "\n".

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 27, 2020 Aug 27, 2020

"Sorry, yes. Does it go in here: where the comma is"
ar = v.split(",");

 

Yes.

 

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 ,
Aug 27, 2020 Aug 27, 2020
LATEST

In place of the comma?

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 ,
Aug 27, 2020 Aug 27, 2020
Thanks, I did but it still does not reset unless the mouse moves and hovers over it. I appreciate your reply and help. any thoughts on separating each item to a new line? I tried /n but it just added /n, not a new line.




Trish Varga

Specialist, Functional Application Support

Application Programming Support

Pellissippi State Community College

10915 Hardin Valley Road

Knoxville, TN 37933 ● 865-694-6409 ● pavarga@pstcc.edu
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 27, 2020 Aug 27, 2020

I notice that there are two copies of the Validate script for "ddtype", which is not normal. Did you edit the code via Edit All JavaScripts? If so, you might have caused irreparable damage to the file and will have to start over from a fresh copy of it.

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 ,
Aug 27, 2020 Aug 27, 2020

It has a ton of fields etc. Can I copy and paste without hurting anything? also never edited that spot, just behind the field.  Sorry for the contact info, did not know I could not reply from my email.

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 27, 2020 Aug 27, 2020

If you didn't edit it from there it should be fine. I just got suspicious because that part appears twice... Is it actually like that, or did you just copy it twice to your reply?

 

You can reply by email, just make sure it doesn't include your private details.

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 ,
Aug 27, 2020 Aug 27, 2020

It is there twice. Is it always bad to edit there? It says it is an edit ecreen. But I saw that too and wondered. I thought maybe there was a bug in Adobe and if I could find the code for doing this somewhere else I could not use the action tab since it does not seem like it is working. 

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 27, 2020 Aug 27, 2020

Yes, very bad. And the name is indeed confusing. You should also not copy the code from there to another file. Best to avoid it altogether, really.

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
Enthusiast ,
Aug 27, 2020 Aug 27, 2020

Do you have other calculations in file? If yes check field calculation order. 

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 ,
Aug 27, 2020 Aug 27, 2020

No nothing.

[Private info removed. -Mod.]

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 27, 2020 Aug 27, 2020

(Each time you reply by email it includes your full contact details in the signature. You should avoid doing 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 ,
Aug 27, 2020 Aug 27, 2020

I decided to create a new form and just copied the dropdown and its text field in to it.

 

This is now in debugger: Does it have any importance?


TypeError: this.getField is not a function
1:XFA:form1[0]:#subform[0]:Header[0]:Body[0]:Type[0]:exit
ReferenceError: UpdateTextField is not defined
2:Field:Validate
ReferenceError: UpdateTextField is not defined
2:AcroForm:ddtype:Validate

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 ,
Aug 27, 2020 Aug 27, 2020

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<AcroForm>
//<ACRO_source>ddtype:Annot1:MouseEnter:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ddtype:Annot1:MouseEnter:Action1 ***********/
this.resetForm(["ddtype"]);

//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>ddtype:Validate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ddtype:Validate ***********/
UpdateTextField(this, "Text1", event.value);

//</ACRO_script>
//</AcroForm>

 

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 27, 2020 Aug 27, 2020

This is an LCD form... You can't edit it in 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
New Here ,
Aug 27, 2020 Aug 27, 2020

I am sorry, I do no tknow what that means. It will allow me to edit. I have had LiveCycle forms I cannot edit in Acrobat but I am phasing them out. This one actually was one that I had to print to PDF and put all my fields back in.

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