Copy link to clipboard
Copied
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.
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
...Copy link to clipboard
Copied
If you post the code you're currently using, we should be able to help.
Copy link to clipboard
Copied
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}
Copy link to clipboard
Copied
Ok, one more question. Where is this script located? What is the field name and what event (calculate, validate, etc.)?
Copy link to clipboard
Copied
I have the javascript on Button21. In the Properties>Actions Tab Mouse Down trigger, Run Java Script is the action. I hope this helps.
Copy link to clipboard
Copied
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;
})();
Copy link to clipboard
Copied
I used the calculation script, it works fabulously. Thank you so much George! I really appreciate it.
Copy link to clipboard
Copied
Thanks for you help
Find more inspiration, events, and resources on the new Adobe Community
Explore Now