3 Replies Latest reply on Aug 30, 2017 10:57 AM by gkaiseril

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

    stevenp1966

      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"

            });

      }

        • 1. Re: submitting a form based upon country, state, then zip code
          try67 MVP & Adobe Community Professional

          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"))

          • 2. Re: submitting a form based upon country, state, then zip code
            stevenp1966 Level 1

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

            • 3. Re: submitting a form based upon country, state, then zip code
              gkaiseril MVP & Adobe Community Professional

              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.