Jump to content
  • 0

Multi-Select List Box Only Stores With Commas



I have a multi-select listbox thanks to this article. The only issue is I need these items separated by ";" instead of ",".



Here is the code with the changes I have made:

<script type="text/javascript">
 var v_state = "[@field:Reason_for_Cancelltaion]" ;
var o_state = document.getElementById("EditRecordReason_for_Cancelltaion") ;
  o_state.multiple = true ;

function f_listbox() {
  if ( v_state.indexOf(";") > 0 ) {
    for (var i=0 ; i < o_state.options.length; i++ ) {
if(o_state[i].value == v_state) {
 break ;
   var o_st = v_state.split("; ") ;
    for (var j=0 ; j < o_st.length; j++) {
     for (var i=0 ; i < o_state.options.length; i++ ) {
 if(o_st[j]== o_state.options[i].value){
  o_state.options[i].selected = true ;
  break ;
 window.onload = f_listbox ;

Even though I have replaced the character it still separates by commas!


Otherwise this functions as intended and I have even paired it with some jquery in order to remove the condition of holding down the control key for multiple selections.



Any and all help is much appreciated!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hello DataCobalt,


As far as I know, multiselect element saves selected items that are separated by comma.


This code only allow to fill the Listbox with saved values that are separated by comma, and if you change the code, it will display values that are separated by ";" but does not save records by this way.


To save values that are separated by ";" you can follow the next steps:

1) Make your current Listbox field Hidden;

2) Add a Virtual field, make it Listbox and set settings as you need.

3) Add a Header&Footer element, click the "Source' button and enter the following code to the Footer

<SCRIPT LANGUAGE="JavaScript">   var fieldName = "cbParamVirtual1";
   var x=document.getElementsByName(fieldName);

  function fill_the_field()
       var fieldName = "cbParamVirtual1";
       var secondFieldName="InsertRecordName";

       var myListBox = document.getElementsByName(fieldName)[0];
       var result = "";
       for (var i = 0; i < myListBox.options.length; i++)
           if (myListBox.options[i].selected)
              result = result + myListBox.options[i].value + ";";
       result = result.slice(0,result.length-1); 
       document.getElementById(secondFieldName).value = result;

Please insert the name of your field instead of "InsertRecordName" and the name of your virtual field instead of "cbParamVirtual1" in both cases, if the Virtual field is not Virtual1.


I 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.

Answer this question...

×   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.

  • Create New...