Expand my Community achievements bar.

SOLVED

Populate Text Box with mulitple selctions from list box

Avatar

Level 2

Hello,

I am new to LiveCycle and searched the forums for an answer as to how to populate multiple selections from a list box to a text field.

I added to the calculate field of the text field the following: TextField14.rawValue = ListBox1.rawValue

Is there a way I can modify this so that the items from the listbox populate the text field so that the values show up side by side (i.e. California, Connecticut, New York) instead of top-down?

Joe

1 Accepted Solution

Avatar

Correct answer by
Level 6

I would use the following JS code in the 'exit' event of the List box

var

ListValue = this.rawValue;

ListValue

= replaceAll(ListValue, "\n", " ,");

TextField1.rawValue

= ListValue;

function

replaceAll(oldStr,findStr, repStr) {

     var srchNdx = 0; // srchNdx will keep track of where in the whole line

     // of oldStr are we searching.

     var newStr = ""; // newStr will hold the altered version of oldStr.

     while (oldStr.indexOf(findStr,srchNdx) != -1)

          // As long as there are strings to replace, this loop

          // will run.

          {

          newStr

+= oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));

          // Put it all the unaltered text from one findStr to

          // the next findStr into newStr.

          newStr

+= repStr;

          // Instead of putting the old string, put in the

          // new string instead.

          srchNdx

= (oldStr.indexOf(findStr,srchNdx) + findStr.length);

          // Now jump to the next chunk of text till the next findStr.

          }

     newStr

+= oldStr.substring(srchNdx,oldStr.length);

     // Put whatever's left into newStr.

     return newStr;

}

Good Luck,

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

I would use the following JS code in the 'exit' event of the List box

var

ListValue = this.rawValue;

ListValue

= replaceAll(ListValue, "\n", " ,");

TextField1.rawValue

= ListValue;

function

replaceAll(oldStr,findStr, repStr) {

     var srchNdx = 0; // srchNdx will keep track of where in the whole line

     // of oldStr are we searching.

     var newStr = ""; // newStr will hold the altered version of oldStr.

     while (oldStr.indexOf(findStr,srchNdx) != -1)

          // As long as there are strings to replace, this loop

          // will run.

          {

          newStr

+= oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));

          // Put it all the unaltered text from one findStr to

          // the next findStr into newStr.

          newStr

+= repStr;

          // Instead of putting the old string, put in the

          // new string instead.

          srchNdx

= (oldStr.indexOf(findStr,srchNdx) + findStr.length);

          // Now jump to the next chunk of text till the next findStr.

          }

     newStr

+= oldStr.substring(srchNdx,oldStr.length);

     // Put whatever's left into newStr.

     return newStr;

}

Good Luck,

Avatar

Level 2

Thanks, I'll give that a try.

Joe