Skip to main content
Known Participant
August 27, 2020
Question

Javascript not working in PDF

  • August 27, 2020
  • 3 replies
  • 2859 views

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!

This topic has been closed for replies.

3 replies

pavargaAuthor
Known Participant
August 27, 2020

No nothing.

[Private info removed. -Mod.]

try67
Brainiac
August 27, 2020

(Each time you reply by email it includes your full contact details in the signature. You should avoid doing that.)

pavargaAuthor
Known Participant
August 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

Inspiring
August 27, 2020

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

Brainiac
August 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.

pavargaAuthor
Known Participant
August 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.

 

try67
Brainiac
August 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.


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.