Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Javascript - Populate text field using data entered

Avatar

Level 1

Hi,

I am learning javascript and need help putting together a script that will do the following:

I have three text fields where users enter data. I would like to take that data and provide a summary in a 4th text field. If a text field is null it should be skipped.

textfield1

textfield2

textfield3

Summary of data entered above should be displayed in textfield4.

text1

text2

text3

Your help would be much appreciated.

Thanks!

varns

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

On the calculate event of the textfield4 put the following (or something like it):

var str1 = "";

var str2 = "";

var str3 = "";

var str4 = "";

if (TextField1.rawValue != null)

    {

    str1 = TextField1.rawValue + "\u000a";

    }

if (TextField2.rawValue != null)

    {

    str2 = TextField2.rawValue + "\u000a";

    }

if (TextField3.rawValue != null)

    {

    str3 = TextField3.rawValue;

    }

str4 = str1 + str2 + str3;

if (str4 > "")
    {
    this.rawValue = str4;
    }
else   
    {
    this.rawValue = "";
    }

You may need to tweak it for your exact needs--good luck!

Stephen

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

Hi,

On the calculate event of the textfield4 put the following (or something like it):

var str1 = "";

var str2 = "";

var str3 = "";

var str4 = "";

if (TextField1.rawValue != null)

    {

    str1 = TextField1.rawValue + "\u000a";

    }

if (TextField2.rawValue != null)

    {

    str2 = TextField2.rawValue + "\u000a";

    }

if (TextField3.rawValue != null)

    {

    str3 = TextField3.rawValue;

    }

str4 = str1 + str2 + str3;

if (str4 > "")
    {
    this.rawValue = str4;
    }
else   
    {
    this.rawValue = "";
    }

You may need to tweak it for your exact needs--good luck!

Stephen

Avatar

Level 1

Stephen,

Thanks! That works great. I'm able to tweak it to suit my needs. I appreciate the help.

varns