Jump to content

Multiple Display Values Selected in Listbox as Comma Separated For Another Field


Recommended Posts

Hey there!

I hope someone can help as I am working on comma delimited values for my app and I already followed the solution provided in this post: 

In that solution, the values selected in the list box are Actual Values and saved into the same field. What I'm attempting to do is obtain those Listbox's Display Values and put them into my 'State' Text(255) Field. Here is my DataPage's listbox setup:

image.png.d0186f4b8a0f83cf6108e59586540d55.png

Is this possible? Thanks!

 

 

Link to comment
Share on other sites

Hi @GetOverHere - this is possible. I found this article: https://stackoverflow.com/questions/28069061/get-the-multiple-selection-as-comma-separated-from-select-box-into-a-text-input that can help you. You can still use the same code from the forum post and add the other one for selecting the display data. Here's the code from your sample use case:

<script>

document.addEventListener('change', assignMultiple);

function assignMultiple() {

  let fieldName = "InsertRecordPriority";

  let x=document.getElementsByName(fieldName);
  x[0].multiple=true;

 var selObj = document.getElementById('InsertRecordPriority');
 var txtTextObj = document.getElementById('InsertRecordState');
 var selected = [];
    
      for(var i=0, l=selObj.options.length; i < l; i++){
          if(selObj.options[i].selected){
               selected.push(selObj.options[i].textContent);
          }
      }

     txtTextObj.value = selected.join(', ');

}
</script>

This is applicable even if the 'State' field is set to the 'Hidden' form element.

Code:

<script>

document.addEventListener('change', assignMultiple);

function assignMultiple() {

  let fieldName = "InsertRecordLISTBOX_FIELDNAME";

  let x=document.getElementsByName(fieldName);
  x[0].multiple=true;

 var selObj = document.getElementById('InsertRecordLISTBOX_FIELDNAME');
 var txtTextObj = document.getElementById('InsertRecordTEXTFIELD_FIELDNAME');
 var selected = [];
    
      for(var i=0, l=selObj.options.length; i < l; i++){
          if(selObj.options[i].selected){
               selected.push(selObj.options[i].textContent);
          }
      }

     txtTextObj.value = selected.join(', ');

}
</script>

Sample Result:

image.png

 

Hope it helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...