Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

submitting a form based upon country, state, then zip code

New Here ,
Aug 24, 2017 Aug 24, 2017

To start, I'm a noob when it comes to JavaScript. So, sorry right off that bat!

What I'm trying to do is email certain individuals based upon country, then state, then zip code within a range. For example, for folks in Texas, only a few handle accounts within a 5 digit zip code range with a prefix of 750**. I've set the field variable in the code for zip_code but, I'm not sure how to have it look for zip codes under a "wildcard" search. The following is the code and I've indicated the lines below in red and bold that I need help with. Please help!

var state = this.getField("state").value;

console.println("state: = " + state);

var country = this.getField("country").value;

console.println("country: = " + country);

var zip_code = this.getField("zip_code").value;

console.println("zip_code: = " + zip_code);

var email = "";

if (country == "          - Select a Country -" && state == "          - Select a State -")

{

   app.alert("You need to select a Country first");

}

else if (country == "USA" && state == "Alaska" || country == "USA" && state == "Colorado" || country == "USA" && state == "Idaho" || country == "USA" && state == "Montana" || country == "USA" && state == "Oregon" || country == "USA" && state == "Utah" || country == "USA" && state == "Washington" || country == "USA" && state == "Wyoming")

{

    email = "beverly.kelly@jstus.com,gam@jstus.com";

}

else if (country == "USA" && state == "Alabama")

{

    email = "joe.gillis@jstus.com,Julie.Green@jstus.com,craig.skok@jstus.com,gam@jstus.com";

}

else if (country == "Brazil" || country == "Chile" || country == "Costa Rica" || country == "Honduras" || country == "Venezuela")

{

    email = "fabio.nakano@jstus.com,odeney.souza@jstus.com,gam@jstus.com";

}

else if (country == "Colombia")

{

    email = "fabio.nakano@jstus.com,odeney.souza@jstus.com,felipe.escoto@jstus.com,gam@jstus.com";

}

else if (country == "Canada")

{

    email = "beverly.kelly@jstus.com,rick.nunemacher@jstus.com,gam@jstus.com";

}

else if (country == "Mexico")

{

    email = "armando.corona@jstus.com,felipe.escoto@jstus.com,omar.teran@jstus.com,jim.kellum@jstus.com,gam@jstus.com";

}

else if (country == "USA" && state == "Arizona")

{

    email = "armando.corona@jstus.com,don.oldfield@jstus.com,doug@dersalesinc.com,jim.kellum@jstus.com,felipe.escoto@jstus.com,gam@jstus.com";

}

else if (country == "USA" && state == "Texas" && zip_code == "750..")

{

    email = "armando.corona@jstus.com,don.oldfield@jstus.com,jim.kellum@jstus.com,gam@jstus.com";

}

else

{

    email = "gam@jstus.com";

}

if (email != "")

{

this.submitForm({

            cURL: "mailto:" + email,

            cSubmitAs: "PDF"

      });

}

TOPICS
Acrobat SDK and JavaScript , Windows
704
Translate
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

Community Expert , Aug 24, 2017 Aug 24, 2017

If the zip codes are purely numeric you can convert the zip_code variable to a number and then use the mathematical comparison, like this:

var zip_code = Number(this.getField("zip_code").value);

...

if (country == "USA" && state == "Texas" && zip_code>=7500 && zip_code<7600)

Also, this is quite confusing:

if (country == "USA" && state == "Alaska" || country == "USA" && state == "Colorado" || country == "USA" && state == "Idaho" || country == "USA" && state == "Montana" || country == "USA" && state ==

...
Translate
Community Expert ,
Aug 24, 2017 Aug 24, 2017

If the zip codes are purely numeric you can convert the zip_code variable to a number and then use the mathematical comparison, like this:

var zip_code = Number(this.getField("zip_code").value);

...

if (country == "USA" && state == "Texas" && zip_code>=7500 && zip_code<7600)

Also, this is quite confusing:

if (country == "USA" && state == "Alaska" || country == "USA" && state == "Colorado" || country == "USA" && state == "Idaho" || country == "USA" && state == "Montana" || country == "USA" && state == "Oregon" || country == "USA" && state == "Utah" || country == "USA" && state == "Washington" || country == "USA" && state == "Wyoming")

You can replace it with:

if (country == "USA" && (state == "Alaska" || state == "Colorado" || state == "Idaho" || state == "Montana" || state == "Oregon" || state == "Utah" || state == "Washington" || state == "Wyoming"))

Translate
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 ,
Aug 30, 2017 Aug 30, 2017

Thank you! That was very helpful. And thank you for the additional information!

Translate
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
LEGEND ,
Aug 30, 2017 Aug 30, 2017
LATEST

Be careful since Zip codes can start with leading zeros it is possible to lose the leading zero if accessing the value as a number. It might be better to use the "valueAsString" property to keep the leading zero.  If one uses the :"valueAsString" property to access the Zip code value then one and sub string or use RegEx object to test the string.

This also applies to SSNs.

Translate
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