Assign values to string list from coach

When we have this kind of scenario  where we need to capture values and assign that to a list variable say "tw.local.ListForExport[i] " , first thing that comes to mind is for loop with something like this.

    <#= tw.local.ListForExport[i] #>= i;

But by now you might have found that this approach is not working. The reason is that, above syntax will be evaluted while loading the coach itself. By the time you wanted to assign some value to the variable the vairable itself is gone and will be replaced with the value in that variable.

One way to successfully assign the string list is to use a multi select element (Hidden) from coach and assign the string list to that multi select element.

You can use similar js code snippet as shown below to achieve this.

      for(i=0;i<someValue;i++) {                                         
          var count=document.getElementById('List1').options.length;      
          document.getElementById('List1').options[count] = new Option(); 
          document.getElementById('List1').options[count].value = i;      
          document.getElementById('List1').options[count].text = i;       
          document.getElementById('List1').options[count].selected = true        }  

In the below screen shot the string list variable "tw.local.ListForExport[]" is assigned to multi select. The values the were assigned to the multiselect element with control ID "List1" with the selected = true will be assigned to the string list and can be carried outside coach.


No comments:

Post a Comment