title: Javascript - How to pass data from table into select options in modal?
body: <p>Sorry for my bad english before. I have already pass data to a modal bootstrap. and already have successed passing data to an <strong>input</strong> in modal. but i dont know how to pass into a <strong>select option</strong> in modal.</p>
  
  <p>how to do that? and displaying in select option with data.</p>
  
  <p>Thanks in advance</p>
  
  <p>here some of my code:</p>
  
  <p><strong>Get data from table:</strong> </p>
  
  <pre><code>&lt;a href="javascript:;"
      data-id="&lt;?php echo $s1['sub_menuid']?&gt;"
      data-mainid="&lt;?php echo $s1['main_menuid']?&gt;"
      data-nama="&lt;?php echo $s1['nama_submenu']?&gt;"
      data-link="&lt;?php echo $s1['link']?&gt;"
      data-icon="&lt;?php echo $s1['icon']?&gt;"
      class="green" data-toggle="modal" data-target="#modal-edit" data-rel="tooltip" title="Edit"&gt;
      &lt;i class="ace-icon fa fa-pencil bigger-130"&gt;&lt;/i&gt;
      &lt;/a&gt;
  </code></pre>
  
  <p><strong>passing into modal via javascript</strong></p>
  
  <pre><code>$('#modal-edit').on('show.bs.modal', function (event) {
               var div = $(event.relatedTarget) // Tombol dimana modal di tampilkan
               var modal          = $(this)
  
               // Isi nilai pada field
               modal.find('#sub_menuid').attr("value",div.data('id'));
               modal.find('#main_menuid').attr("value",div.data('mainid'));
               modal.find('#nama_submenu').attr("value",div.data('nama'));
               modal.find('#link').attr("value",div.data('link'));
               /*modal.find('#icon').attr("value",div.data('icon'));*/
           });
  </code></pre>
  
  <p><strong>modal-edit:</strong></p>
  
  <pre><code>&lt;div aria-hidden="true" aria-labelledby="ModalLabel" role="dialog" tabindex="-1" id="modal-edit" class="modal fade"&gt;
          &lt;div class="modal-dialog"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                      &lt;button aria-hidden="true" data-dismiss="modal" class="close" type="button"&gt;×&lt;/button&gt;
                      &lt;h4 class="modal-title"&gt;&lt;b&gt;Edit Sub Menu Level 1&lt;/b&gt;&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;form class="form-horizontal" id="form-edit" action="&lt;?php echo base_url('sub_menu_level_1/edit')?&gt;" method="post" enctype="multipart/form-data" role="form"&gt;
                      &lt;div class="modal-body"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label class="col-md-3 col-sm-2 control-label"&gt;Nama Sub Menu&lt;/label&gt;
                              &lt;div class="col-md-8"&gt;
                                  &lt;input type="hidden" id="sub_menuid" name="sub_menuid"&gt;
                                  &lt;input type="text" id="nama_submenu" class="form-control" name="nama_submenu" placeholder="Nama menu"&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label class="col-md-3 col-sm-2 control-label"&gt;Pilih Main Menu&lt;/label&gt;
                              &lt;div class="col-md-8"&gt;
                                  &lt;select class="form-control" id="main_menuid" name="main_menuid"&gt;
                                  &lt;option value=""&gt;&lt;/option&gt;
                                  &lt;?php foreach($main_menu as $mm) { ?&gt;
                                  &lt;option value="&lt;?php echo $mm['main_menuid']?&gt;"&gt;&lt;?php echo ucwords($mm['nama_mainmenu'])?&gt;&lt;/option&gt;
                                  &lt;?php } ?&gt;
                                  &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label class="col-md-3 col-sm-2 control-label"&gt;Link&lt;/label&gt;
                              &lt;div class="col-md-8"&gt;
                                  &lt;input type="text" id="link" class="form-control" name="link" placeholder="link"&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="modal-footer"&gt;
                          &lt;button type="button" class="btn btn-warning" data-dismiss="modal"&gt; Batal&lt;/button&gt;
                          &lt;button id="btn-submit-edit" class="btn btn-info" type="submit"&gt; Simpan&amp;nbsp;&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!-- END Modal edit --&gt;
  </code></pre>