Check texbox for specific word

New Here ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

I am trying to figure out how to check a certain textbox contains a certain word in either upper or lowercase (XPO). If it does, then perform one action. If not then perform a different action, below is the code i currently am working with but it dosent seem to work.

var cCustomerName = this.getField("CUSTOMER NAME").value;

if (cCustomerName == "XPO"||"xpo"){

ccAddress1 = ("dan.somename@somewhere.com" + "; " + "eps@somewhere.com" + "; " + "mark.b@somewhere.com" + "; " +"jeff.s@somewhere.com")

}

else

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

104

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Apr 09, 2019 Apr 09, 2019
The best way to perform a test on text, is with a Regular Expression:https://acrobatusers.com/tutorials/text-matching-regular-expressions If XPO is this only word in the field, then this test will workif(/^xpo$/i.test(cCustomerName)){.. Do stuff ...}But if XPO is only part of the text, then this will workif(/xpo/i.test(cCustomerName)){.. Do stuff ...}If XPO needs to be a whole word in the text, then use thisif(/\wxpo\w/i.test(cCustomerName)){.. Do stuff ...}

Likes

Translate

Translate
Adobe Community Professional ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

The best way to perform a test on text, is with a Regular Expression:

https://acrobatusers.com/tutorials/text-matching-regular-expressions

If XPO is this only word in the field, then this test will work

if(/^xpo$/i.test(cCustomerName))

{

.. Do stuff ...

}

But if XPO is only part of the text, then this will work

if(/xpo/i.test(cCustomerName))

{

.. Do stuff ...

}

If XPO needs to be a whole word in the text, then use this

if(/\wxpo\w/i.test(cCustomerName))

{

.. Do stuff ...

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

LATEST

Thanks Thom, this seems to work out well. I would have never figured it out and it works for any combination whether it be caps or lowercase. Perfect!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines