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

Creating a custom String of text

New Here ,
Feb 04, 2016 Feb 04, 2016

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.

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

LEGEND , Feb 04, 2016 Feb 04, 2016

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 arra

...
Translate
LEGEND ,
Feb 04, 2016 Feb 04, 2016

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

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 ,
Feb 04, 2016 Feb 04, 2016

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}

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 ,
Feb 04, 2016 Feb 04, 2016

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

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 ,
Feb 04, 2016 Feb 04, 2016

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

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 ,
Feb 04, 2016 Feb 04, 2016

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;

})();

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 ,
Feb 04, 2016 Feb 04, 2016
LATEST

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

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 ,
Feb 04, 2016 Feb 04, 2016

Thanks for you help

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