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

Checking length of field

Gheezer
Registered: Feb 16 2009
Posts: 19
Answered

I have the following script that checks the length of a specific field and determines if the length of the value is correct. The problem I'm having is that when the function is executed from a field to check the length of another fields value, it comes back false, but work correctly if executed from a field to check it's own value length.
 
If there is an easier way to do this, then I'm for it. I appreciate any and all help.
 
The function is fired off with the following 2 ways:
//executes from directly from field to check if lenght is correct
//the length of the field should equal 9
Check_Required("9");
//executes from another field to check field length
// the length of the field should be 9 and here is the field name to check
Check_Required("9", "field_name");
 
function Check_Required(iLEN, sNAM)
{
var ETN = this.getField((typeof sNAM == "undefined")?event.target.name:sNAM).name;
var EVL = (typeof sNAM == "undefined")?event.value.length:this.getField(ETN).value.length;
if(iLEN == "~") //text field with no specific length, just not zero
{
if(EVL != 0)
Format_Correct(ETN);
else
Format_Incorrect(ETN);
}
else
{
//REQUIRED NUMBER OF CHARACTERS
if(EVL == iLEN)
Format_Correct(ETN);
else
Format_Incorrect(ETN);
}
}
 
function Format_Correct(ETN)
{
app.alert("format correct");
}
 
function Format_Incorrect(ETN)
{
app.alert("format incorrect");
}

My Product Information:
Acrobat Pro 8.1.7, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
Change these two lines:

var ETN = this.getField((typeof sNAM == "undefined")?event.target.name:sNAM).name;
var EVL = (typeof sNAM == "undefined")?event.value.length:this.getField(ETN).value.length;


To this:

var ETN = typeof sNAM == "undefined" ? event.target.name : sNAM;
var EVL = typeof sNAM == "undefined" ? event.value.length : getField(ETN).valueAsString.length;


Gheezer
Registered: Feb 16 2009
Posts: 19
That was way to easy. I thank you from the bottom of my heart.js 8^)

George_Johnson wrote:
Change these two lines:var ETN = this.getField((typeof sNAM == "undefined")?event.target.name:sNAM).name;
var EVL = (typeof sNAM == "undefined")?event.value.length:this.getField(ETN).value.length;


To this:

var ETN = typeof sNAM == "undefined" ? event.target.name : sNAM;
var EVL = typeof sNAM == "undefined" ? event.value.length : getField(ETN).valueAsString.length;