These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Button to Highlight required fields

Grumlin3
Registered: Dec 5 2007
Posts: 12

I am trying to create a button that highlights all the required fields ,however,the Java script that I have is not working. Can anyone tell me what I am doing wrong?
 
Java Scripts:
 
Create two buttons in a document containing form fields. One button has the JavaScript mouse up action showRequired();
that will highlight all required fields, the other button has the following mouse up action restoreRequired(); that restores the fields to the appearance state they were in before the showRequired() function executed.
 
The script that follows is a document-level JavaScript that defines the functions called by the two buttons.
 
var oFieldNames = new Object(); // used to save the appearance of the fields
function showRequired() {
// Search through all fields for those that are set to required, excluding
// any button fields.
for ( var i=0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if ( (f.type != "button") && f.required) {
// Save appearance data in oFieldNames
oFieldNames[fname]={ strokeColor: f.strokeColor,
fillColor: f.fillColor};
// Assign a red boundary color, and fill color
f.strokeColor=color.red;
f.fillColor=app.runtimeHighlightColor;
}
}
}
// Now restore the fields.
function restoreRequired() {
if ( typeof oFieldNames == "object") {
for ( var o in oFieldNames ) {
var f = this.getField(o);
f.strokeColor=oFieldNames[o].strokeColor;
f.fillColor=oFieldNames[o].fillColor;
}
}
oFieldNames = new Object();
}

I work for Regis University working on a Masters.

My Product Information:
Acrobat Pro 7.0.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Have you done any Debug? Where isn't it working? Is an exception (Look in the JavaScript Console) thrown? Are the fields aquired? are the colors saved? is the problem with setting colors?

Please do some debug and narrow it down.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Grumlin3
Registered: Dec 5 2007
Posts: 12
How do I debug? I am copying and pasting the first part of the script in a button, When I go to test it; none of the text boxes that I have marked required (but did not fill in)show with a red box around them. There are no exceptions thrown. ???

I work for Regis University working on a Masters.