7 Replies Latest reply on Feb 4, 2016 5:27 PM by senechia

    Creating a custom String of text

    senechia

      I have 4 text boxes. They are Event, City, Email, and String

      If Las Vegas is entered in the City text box, I want the String text box to read "City: Las Vegas"

      If BK is entered in the Event text box, and Las Vegas is entered in the City text box, I want the String text box to read "Event: BK City: Las Vegas"

      If blah@gmail.com is entered in the Email text box, and there is no data in Event, or City text boxes, I want the String text box to read "Email: blah@gmail.com

      I can get the data into the String text box, but if any of the 3 text boxes are empty my String text box reads something like this "Event: Email: blah@gmail.com City:"

      If any of the Event, City, and/or Email text boxes are empty, I don't want the text associated with the data to show up in the Srtring text box.

      I am a novice at javascript. Any help is much appreciated.

        • 1. Re: Creating a custom String of text
          George_Johnson MVP & Adobe Community Professional

          If you post the code you're currently using, we should be able to help.

          • 2. Re: Creating a custom String of text
            senechia Level 1

            var one = this.getField("Event");

            var two = this.getField("City");

            var three = this.getField("Email");

            var four = this.getField("String");


            {four.value="Event: "+one.value+" City: "+two.value+" Email: "+three.value}

            • 3. Re: Creating a custom String of text
              senechia Level 1

              Thanks for you help

              • 4. Re: Creating a custom String of text
                George_Johnson MVP & Adobe Community Professional

                Ok, one more question. Where is this script located? What is the field name and what event (calculate, validate, etc.)?

                • 5. Re: Creating a custom String of text
                  senechia Level 1

                  I have the javascript on  Button21. In the Properties>Actions Tab Mouse Down trigger, Run Java Script is the action. I hope this helps.

                  • 6. Re: Creating a custom String of text
                    George_Johnson MVP & Adobe Community Professional

                    OK. You should use Mouse Up instead, and the script could be changed to:

                     

                    // Mouse Up script for a button

                    (function () {

                     

                        // Get the field values, as strings

                        var sEvent = this.getField("Event").valueAsString;

                        var sCity = this.getField("City").valueAsString;

                        var sEmail = this.getField("Email").valueAsString;

                     

                        // Get a reference to the output field

                        var fOutput = this.getField("String");

                        var sOutput = "", aOutput = [];  // Initialize output string and array

                     

                        // Set the output array

                        if (sEvent) {

                            aOutput.push("Event: " + sEvent);

                        }

                     

                        if (sCity) {

                            aOutput.push("City: " + sCity);

                        }

                     

                        if (sEmail) {

                            aOutput.push("Email: " + sEmail);

                        }

                     

                        // Join the elements of the array into a string, separated by a space

                        if (aOutput.length > 0) {

                            sOutput = aOutput.join(" ");

                        }

                     

                        // Set the field value to the output string

                        fOutput.value = sOutput;

                     

                    })();

                     

                     

                    If you want it to happen automatically, you could use the following custom calculation script for the "String" field

                     

                    // Custom calculation script for String field

                    (function () {

                     

                        // Get the field values, as strings

                        var sEvent = this.getField("Event").valueAsString;

                        var sCity = this.getField("City").valueAsString;

                        var sEmail = this.getField("Email").valueAsString;

                     

                       var sOutput = "", aOutput = [];  // Initialize output string and array

                     

                        // Set the output array

                        if (sEvent) {

                            aOutput.push("Event: " + sEvent);

                        }

                     

                        if (sCity) {

                            aOutput.push("City: " + sCity);

                        }

                     

                        if (sEmail) {

                            aOutput.push("Email: " + sEmail);

                        }

                     

                        // Join the elements of the array into a string, separated by a space

                        if (aOutput.length > 0) {

                            sOutput = aOutput.join(" ");

                        }

                     

                        // Set this field's value to the output string

                        event.value = sOutput;

                     

                    })();

                    • 7. Re: Creating a custom String of text
                      senechia Level 1

                      I used the calculation script, it works fabulously. Thank you so much George! I really appreciate it.