Forum Moderators: open

Message Too Old, No Replies

desperate help needed (javascript in acrobat)

         

wardy83

9:57 am on Jul 25, 2006 (gmt 0)

10+ Year Member



Hi could anyone please tell me where I am going wrong with the code below.. what I want it to do is when the user clicks print, its checks all fields with an asterix to see if they are filled in.. if not it displays prompt.. it also prints the current page as well.

I was also wondering how easy it will be to hide some text if it is printed via this button, but the text is still visible if the user prints via menu bar.

The code is being used in adobe acrobat, but I would believe that the fundementals will be the same.

Here is my code, all help greatly recieved... many thanks! :

function validateFields()
{

//a counter for the number of empty fields
var flg = 0

// count all the form fields
var n = this.numFields

//create an array to contain the names of required fields
//if they are determined to be empty

var fArr = new Array();

//loop through all fields and check for those that are required
// all fields that have a '*' in their tool tip are required

for(var i = 0;i
var fn = this.getNthFieldName(i);
var f = this.getField(fn);

//tool tip is the fields\'s 'userName' property;
var tt = f.userName

//test for the '*';
if(tt.indexOf('*')!=-1 && f.value == f.defaultValue){

//increment the counter of empty fields;
flg++;
//add the fields userName (tool tip) to the list of empty field names;
fArr[fArr.length] = tt;
}
}

//now display a message if there are empty fields and print current page without print popup

if(flg>0){
app.'There are '+flg+' fields that require a value\n\n'+ fArr,3)
}
else{
this.print();
}

}
Posted: 25 Jul 2006 06:25 PM
Left Button SpacerSend user an email email¦View user's profile profileRight Button Spacer

wardy83

10:44 am on Jul 25, 2006 (gmt 0)

10+ Year Member



I'm stupid...

Forgot to mention the above code does work for checking the fields but as some of the fields need to have just the number 0 in them (which isn't actually a number) the fields are still being prompted as empty... what I want is for it to only prompt when fields has nothing in it at all.

Is their an easy way around this?