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

event.target.value question

MadMich
Registered: Aug 29 2007
Posts: 38
Answered

I'm trying to check field value using a button action. If it is empty, I want to add the text "N/A". If not empty, leave existing text.

Here is my code but I can't get it to work?

var f = this.getField("codeNumber").value;
event.target.value = event.target.defaultValue;
if (f.value ==""){
f.value = "N/A";
}else{
f.value = event.target.Value; }

Thanks in advance

My Product Information:
Acrobat Pro 8.1.2, Macintosh
MadMich
Registered: Aug 29 2007
Posts: 38
I think I've worked it out but I would still like to know how to identify a default value.

Here's the code


var fieldName = "codeNumber"; // establish field name to process
if (getField(fieldName).value == "")
this.getField(fieldName).value = "N/A"
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You can also use other properties of the "event" object like "targetName" or "target.name".


if (getField(event.targetName).value == "")
this.getField(event.targetName).value = "N/A"

If using version 4 of Acrobat:

if (getField(event.target.name).value == "")
this.getField(event.target.name).value = "N/A"


The 'event.target' is the object that triggered the action so to access the "value" property one needs to supply more information. Like:

if (event.target.value == "")
event.target.value = "N/A"

George Kaiser

MadMich
Registered: Aug 29 2007
Posts: 38
Thanks, i'll use these in the future.