title: How to add options to bootstrap multiselect checkbox drop down via fancybox
body: <p>I have multiselect checkbox drop down. I created fancy box and by entering text field values on the fancy box and by clicking on submit button.</p>
  
  <p>I need to add drop down values or update drop down values dynamically.Please help. </p>
  
  <p>View:-</p>
  
  <pre><code>@{
      ViewBag.Title = "jqtree";
  }
  
  &lt;h2&gt;jqtree&lt;/h2&gt;
  &lt;div class="container"&gt;
  &lt;div class="panel-group" id="accordion"&gt;
    &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
        &lt;h4 class="panel-title"&gt;
          &lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne"&gt;
            &lt;span class="glyphicon glyphicon-minus"&gt;&lt;/span&gt;
            Collapsible Group Item #1
          &lt;/a&gt;
        &lt;/h4&gt;
      &lt;/div&gt;
      &lt;div id="collapseOne" class="panel-collapse collapse in"&gt;
        &lt;div class="panel-body"&gt;
          Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
        &lt;h4 class="panel-title"&gt;
          &lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"&gt;
            &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;
            hello
          &lt;/a&gt;
        &lt;/h4&gt;
      &lt;/div&gt;
      &lt;div id="collapseTwo" class="panel-collapse collapse"&gt;
        &lt;div class="panel-body"&gt;
         &lt;p class="message success" id="callback"&gt;Callback target&lt;/p&gt;
         &lt;select multiple="multiple" size="5" id="inptProduct"&gt;
          @*&lt;optgroup label="Group One"&gt;*@
              &lt;option value="option1"&gt;Option 1&lt;/option&gt;
              &lt;option value="option2"&gt;Option 2&lt;/option&gt;
              &lt;option value="option3"&gt;Option 3&lt;/option&gt;
         @* &lt;/optgroup&gt;*@
          @*&lt;optgroup label="Group Two"&gt;
              &lt;option value="option4"&gt;Option 4&lt;/option&gt;
              &lt;option value="option5"&gt;Option 5&lt;/option&gt;
              &lt;option value="option6"&gt;Option 6&lt;/option&gt;
              &lt;option value="option7"&gt;Option 7&lt;/option&gt;
          &lt;/optgroup&gt;*@
          &lt;/select&gt;
  
            &lt;a href="@Url.Action("To_view", "TodoList")" id="a1"&gt;
        &lt;span class="glyphicon glyphicon-plus-sign"&gt;&lt;/span&gt; 
        &lt;/a&gt;         
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
        &lt;h4 class="panel-title"&gt;
          &lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseThree"&gt;
            &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;
            Collapsible Group Item #3
          &lt;/a&gt;
        &lt;/h4&gt;
      &lt;/div&gt;
        &lt;div id="collapseThree" class="panel-collapse collapse"&gt;
        &lt;div class="panel-body"&gt;
          Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
        &lt;/div&gt;
        &lt;/div&gt;
      &lt;link rel="stylesheet" type="text/css" href="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/jquery.multiselect.css" /&gt;
      &lt;link rel="stylesheet" type="text/css" href="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/assets/style.css" /&gt;
     &lt;link rel="stylesheet" type="text/css" href="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/assets/prettify.css" /&gt;
        &lt;link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css" /&gt;
        &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" type="text/css" media="screen" /&gt;
        &lt;link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css"/&gt;
      &lt;link href="~/css/bt.css" rel="stylesheet" type="text/css" /&gt;
  
      &lt;script src="~/Scripts/jquery-1.9.1.min.js"&gt;&lt;/script&gt;
        &lt;script src="~/Scripts/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript" src="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/src/jquery.multiselect.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/assets/prettify.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"&gt;&lt;/script&gt;
  
      &lt;script src="~/Scripts/bt.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <h2>Js file:-</h2>
  
  <pre><code>$('.collapse').on('shown.bs.collapse', function () {
      $(this).parent().find(".glyphicon-plus").removeClass("glyphicon-plus").addClass("glyphicon-minus");
  }).on('hidden.bs.collapse', function () {
      $(this).parent().find(".glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus");
  });
  $(function () {
      var $callback = $("#callback");
      var optionsAsString = "";
      $('#btn1').click(function (e) {
          e.preventDefault();
          optionsAsString += "&lt;option value='" + $('#txt1').val() + "'&gt;" + $('#txt1').val() + "&lt;/option&gt;";
          alert(optionsAsString);
      });
      $("select").append(optionsAsString);
      $("select").multiselect({
  
          click: function (event, ui) {
              $("#callback").text(ui.value + ' ' + (ui.checked ? 'checked' : 'unchecked'));
          },
          beforeopen: function () {
              $("#callback").text("Select about to be opened...");
          },
          open: function () {
              $("#callback").text("Select opened!");
          },
          beforeclose: function () {
              $("#callback").text("Select about to be closed...");
          },
          close: function () {
              $("#callback").text("Select closed!");
          },
          checkAll: function () {
              $("#callback").text("Check all clicked!");
          },
          uncheckAll: function () {
              $("#callback").text("Uncheck all clicked!");
          },
          optgrouptoggle: function (event, ui) {
              var values = $.map(ui.inputs, function (checkbox) {
                  return checkbox.value;
              }).join(", ");
  
              $("#callback").html("&lt;strong&gt;Checkboxes " + (ui.checked ? "checked" : "unchecked") + ":&lt;/strong&gt; " + values);
          }
      });
      $('#a1').fancybox({
          transitionIn: "elastic",
          transitionOut: "elastic",
          overlayShow: false,
          target: this,
          orig: $("img", this),
          titlePosition: "inside",
          titleFormat: titleFormat,
          type: 'iframe',
          padding: 0,
          closeClick: false,
  
      });
      var titleFormat = function (titleStr, currentArray, currentIndex, currentOpts) {
          titleStr = '&lt;span id="fancybox-title-' + currentOpts.titlePosition + '"&gt;' + titleStr + '&lt;\/span&gt;';
          return titleStr;
      };
  
  });
  </code></pre>