Copy link to clipboard
Copied
Hello,
I have a document level javascript that is looking for character strings to determine a result.
Why would it throw this error?
function webaddress() {
var one = this.getField("CompanyName");
var two = this.getField("WebAddress");
var three = this.getField("dealerCSZ");
var n = three.indexOf("MN,");
var n1 = three.indexOf("IN,");
var n2 = three.indexOf("OH,");
// evaluate address for proper name
if (n.value>=1)
{
one.value='TRUCK COUNTRY USED TRUCK CENTER';
two.value='www.truckcountry.com';
}
else if (n1.value>0 || n2.value>0)
{
one.value='STOOPS FREIGHTLINER - QUALITY TRUCKS';
two.value='www.stoops.com';
}
else
{
one.value='TRUCK COUNTRY';
two.value='www.truckcountry.com';
}
}
webaddress(); // call my function
Use:
if (n >= 1)
Info: the variables n, n1, and n2 are local variables of the function.
Copy link to clipboard
Copied
You must use the value of the field. Example:
var n = three.value.indexOf("MN,");
Copy link to clipboard
Copied
Actually, you should use the valueAsString property instead of value - otherwise the code will throw an exception if the value is not already a string:
var n = three.valueAsString.indexOf("MN,");
Copy link to clipboard
Copied
All - thanks for the quick reply.
I added 'valueAsString' and am no longer getting an error.
However, the variables n, n1, and n2 are all showing 'undefined' when I print them out.
Is the indexOf method able to evaluate a comma?
Here is the current script.
function webaddress() {
var one = this.getField("CompanyName");
var two = this.getField("WebAddress");
var three = this.getField("dealerCSZ");
var n = three.valueAsString.indexOf("MN,");
var n1 = three.valueAsString.indexOf("IN,");
var n2 = three.valueAsString.indexOf("OH,");
// evaluate address for proper name
if (n.value>=1)
{
one.value='TRUCK COUNTRY USED TRUCK CENTER';
two.value='www.truckcountry.com';
}
else if (n1.value>0 || n2.value>0)
{
one.value='STOOPS FREIGHTLINER - QUALITY TRUCKS'; two.value='www.stoops.com';
}
else
{
one.value='TRUCK COUNTRY';
two.value='www.truckcountry.com';
}
}
webaddress(); // call my function
Copy link to clipboard
Copied
Use:
if (n >= 1)
Info: the variables n, n1, and n2 are local variables of the function.
Copy link to clipboard
Copied
You are absolutely correct!
Thanks for your help.
Works great.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now