title: Get value of multiselect box using jQuery or pure JS
body: <p>In the code shown below, how to get the values of multiselect box in function <code>val()</code> using jQuery or pure JavaScript?</p>
  
  <pre><code>&lt;script&gt;
      function val() {
          //Get values of mutliselect drop down box
      }
  
      $(document).ready(function () {
          var flag = 0;
          $('#emp').change(function () {
              var sub = $("OPTION:selected", this).val()
              if (flag == 1) $('#new_row').remove();
              $('#topics').val('');
              var html = '&lt;tr id="new_row" class="new_row"&gt;&lt;td&gt;Topics:&lt;/td&gt;&lt;td&gt;  &lt;select    id="topic_l" name="topic_l" class="topic_l" multiple="multiple"&gt;';
              var idarr = new Array();
              var valarr = new Array(); { %
                  for top in dict.tops %
              }
              idarr.push('{{top.is}}');
              valarr.push('{{pic.ele}}'); { % endfor %
              }
              for (var i = 0; i &lt; idarr.length; i++) {
                  if (sub == idarr[i]) {
                      html += '&lt;option value="' + idarr[i] + '" &gt;' + valarr[i] + '&lt;/option&gt;';
                  }
              }
              html += '&lt;/select&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;';
              $('#tops').append(html);
              flag = 1;
          });
      });
  &lt;/script&gt;
  Emp:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;select id="emp" name="emp"&gt;
      &lt;option value=""&gt;&lt;/option&gt;
      &lt;option value="1"&gt;1&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;div name="tops" id="tops"&gt;&lt;/div&gt;
  
  &lt;input type="submit" value="Create Template" id="create" onclick="javascript:var ret=val();return ret;"&gt;
  </code></pre>