Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How do you populate 1 text box with multiple dropdown values

Avatar

Former Community Member

I can populate a text box with a value from a dropdown, however if I have 2 dropdown values going to the same text box (multi-line), the second dropdown value removes the first value.

(Similar code on Dropdown 1 and Dropdown 2)

Change Event - JavaScript

if(xfa.event.newText == 'No'){

form1.page1.subform2.description.rawValue="No location listed";

}

if(xfa.event.newText == "Partial location"){

form1.page1.subform2.description.rawValue="Partial location listed";

}

Do I have to Concat the fields in the 1 text field to get it to list multiple dropdown values, and if so how do I do that?

Thanks in advance for your help.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Solved:

Place this script in the subform root level in the FormReady event -JavaScript.

var oList = this.getDeltas ();

for (i=0; i < oList.length; i ++)

{

   var oDelta = oList.item(i);

   oDelta.restore ();

}

Answer was found at http://forms.stefcameron.com/2008/09/29/restoring-the-of-your-form/

View solution in original post

11 Replies

Avatar

Former Community Member

Is this what you are after?

// form1.page1.subform1.tf::calculate - (JavaScript, client)

if (form1.page1.subform1.color.selectedIndex != -1 && form1.page1.subform1.fruit.selectedIndex != -1) {

          this.rawValue = form1.page1.subform1.color.rawValue + "\n" + form1.page1.subform1.fruit.rawValue;

}

else {

          if (form1.page1.subform1.color.selectedIndex != -1 && form1.page1.subform1.fruit.selectedIndex == -1) {

    this.rawValue = form1.page1.subform1.color.rawValue;

          }

          else {

    if (form1.page1.subform1.color.selectedIndex == -1 && form1.page1.subform1.fruit.selectedIndex != -1) {

      this.rawValue = form1.page1.subform1.fruit.rawValue;

    }

          }

}

Steve

Avatar

Former Community Member

Thanks Steve for your help on this, you are amazing!

That is close.  I am actually trying to display specific values from the dropdown. 

So for your example, lets say I want just Red and Green values from the color field and Apples and Pears from the Fruit field to populate the textbox.  I also want to change the drop down value of "Red" to say "Ruby Red" to in the Text box.  Is that possible?

Avatar

Former Community Member

YAY - I got it figured out!

On Color Drop Down - Change Event, JavaScript

if (xfa.event.newText == 'Red') {

     form1.page1.subform1.textbox.rawValue="Ruby Red";

}

if (xfa.event.newText == 'Green'){

     form1.page1.subform1.textbox.rawValue="Light Green";

}

On Fruit Drop Down - Change Event, JavaScript

if (xfa.event.newText == 'Apple') {

     form1.page1.subform1.textbox.rawValue="Granny Smith";

}

if (xfa.event.newText == 'Pear'){

     form1.page1.subform1.textbox.rawValue="Bartlett";

}

On Text Box - Calculate Event, JavaScript

this.rawValue = form1.page1.subform1.color.rawValue + "\n" + form1.page1.subform1.fruit.rawValue; 

Thank you Steve for pointing me into the right direction.

Avatar

Former Community Member

It works for only a few drop down values, if I get more than 6 going it displays only the last drop-down value.  What am I doing wrong?

Avatar

Former Community Member

Changed the event from Change to Calculated and then the value type "Calculated - Read only" to "Calculated - User can override" and it didn't work.  Text box is blank.

Avatar

Former Community Member

HUMMMMM – How would I add the dropdown fields to the text box?

Eve Tracy

Avatar

Former Community Member

You need to remove the script from each drop-down change event and put all the script on the description calculate event. For example,

// form1.NonCompliancePage.subform2.description::calculate - (JavaScript, client)

var str = "";

if (form1.recordKeepingPage.RecordKeeping.rk_BusName.rawValue == "Required Records - No business name listed" || form1.recordKeepingPage.RecordKeeping.rk_BusName.rawValue == "Required Records - Partial business name listed") {

          if (form1.recordKeepingPage.RecordKeeping.rk_BusName.rawValue == "Required Records - No business name listed") {

                    str = "Required Records-No business name listed" + "\n";

          }

          else {

                    str = "Required Records - Partial business name listed" + "\n";

          }

}

if (form1.recordKeepingPage.RecordKeeping.rk_StAddress.rawValue == "No" || form1.recordKeepingPage.RecordKeeping.rk_StAddress.rawValue == "Partial address" || form1.recordKeepingPage.RecordKeeping.rk_StAddress.rawValue == "P.O Box only") {

          if (form1.recordKeepingPage.RecordKeeping.rk_StAddress.rawValue == "No") {

                    str =  str + "Required Records-No address of the application listed" + "\n";

          }

          else {

                    if (form1.recordKeepingPage.RecordKeeping.rk_StAddress.rawValue == "Partial address") {

                              str = str + "Required Records-Partial address listed" + "\n";

                    }

                    else {

                              str = str + "Required Records-PO Box only listed" + "\n";

                    }

          }

}

this.rawValue = str;

Steve

Avatar

Former Community Member

Thank you so much!  This is exactly what I was wanting to do, you are Amazing!

Avatar

Former Community Member

I have another question regarding the script to populate a text box with multiple dropdown values. 

How do you save the form state (keep the page visible after it has been saved)?  This form will be connected to a signature pad, so it has to be certified and preserve scripting changes to form when saved is set to manually.  

I can save the form state of several other hidden pages using this code in the initialize event:

 

if

(this.rawValue==1)

{subformName.presence="visible";}

else

{subformName.presence="hidden";}

However, since I have multiple fields writing to a text box using the calculated event, I can't seem to save the form state using the code above. 

Please help, I have been searching forums and can not find a solution to this one.

Avatar

Correct answer by
Former Community Member

Solved:

Place this script in the subform root level in the FormReady event -JavaScript.

var oList = this.getDeltas ();

for (i=0; i < oList.length; i ++)

{

   var oDelta = oList.item(i);

   oDelta.restore ();

}

Answer was found at http://forms.stefcameron.com/2008/09/29/restoring-the-of-your-form/

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----