Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 = "";
}
}
Copy link to clipboard
Copied
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!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now