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

Pull document level javascript

Explorer ,
Feb 02, 2016 Feb 02, 2016

I have a working JavaScript (below) but, because it will ultimately affect 9 fields, it will get very long.  The changes in a text field are triggered by whether a check box is checked or not so currently the JavaScript is in the Mouse Up Action of the check box. I assume a Doc Level is more efficient? I have other Doc Level scripts which are contained within 1 field but since this is triggered by the check box I expect I need a different method. I have a Reset Button on the form which would also need the ability to reset those specific fields.

Working JavaScript in Mouse Up Action of check box:

var r = getField("cb7");
var s = getField("III.A.3");

if (r.type === "checkbox" && r.value == "additional victims on page 2") {
s.readonly = false;
s.required = true;
s.fillColor=["G",.8];
s.value = "";

}

else

if (r.type === "checkbox" && r.value != "additional victims on page 2"){
s.readonly = true;
s.required = false;
s.fillColor=color.transparent;
s.value = "";

}

Thanks

Meabh

TOPICS
Acrobat SDK and JavaScript , Windows
707
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 ,
Feb 02, 2016 Feb 02, 2016

For document-level JavaScripts, it is best to organize them into functions.

function myFunction1 () {

  // function code here.

}

function myFunction2 () {

  // function code here.

}

Then in your form fields' JavaScript, you can simply call the appropriate function:

myFunction1 ();

I hope this helps. -Rick

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
Explorer ,
Feb 02, 2016 Feb 02, 2016

I had the thought of using an Array for the text field name and pull the function that way.  I used 'required' as the Array name, changed all the text field names to start with 'required' with this code as a Doc Level and required(event.target.name) in the check box Action. Still no joy.

function required(fieldName){
var r = getField("cb7");
var s = getField(required);

if (r.type === "checkbox" && r.value == "additional victims on page 2") {
s.readonly = false;
s.required = true;
s.value = "";


}

else

if (r.type === "checkbox" && r.value == "additional victims on page 2") {
s.readonly = true;
s.required = false;
s.value = "";


}

else
{
s.readonly = true;
s.required = false;
s.value = "";
}
}

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
Explorer ,
Feb 02, 2016 Feb 02, 2016
LATEST

The eagle eyed experts no doubt would have noticed the lack of "" that should be with the field name 'required' a lot sooner than I did but with that little addition this works!!

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