title: How to run a javascript function from a modal window?
body: <p>I have a select, which change in value calc executes a function.</p>
  
  <pre><code>$("#modelo").change(function () {
              var id_modelo = $(this).val();
              $.ajax({
                  type: "POST",
                  url: "&lt;?php echo base_url(); ?&gt;cotizacion/getimages",
                  dataType: 'json',
                  async: true,
                  data: "id_modelo=" + id_modelo,
                  beforeSend: function () {
  
                      //$('#msgUsuario').html('&lt;span&gt;&lt;/span&gt;');
                  },
                  success: function (data) {
                      $("#imagenesnaves").html(data);
                      $('#contenimages').show();
                  }
              });
              return false;
          });
  </code></pre>
  
  <p>which runs the following method
  controller</p>
  
  <pre><code>public function getImages() {
          $id_modelo = $this-&gt;input-&gt;post('id_modelo', TRUE);
          $imagenes = $this-&gt;Modelos_model-&gt;getImages($id_modelo);
          $output = NULL;
          if ($imagenes) {
              $index = 0;
              foreach ($imagenes as $fila) {
                  $output .= '&lt;div class="file-preview-thumbnails"&gt;
                                  &lt;div class="file-live-thumbs"&gt;
                                      &lt;div class="file-preview-frame"  data-fileindex="4" data-template="image"&gt;
                                          &lt;div class="kv-file-content"&gt;
                                              &lt;img src="' . base_url() . 'uploads/' . $fila-&gt;name . '" class="kv-preview-data file-preview-image" style="width:auto;height:160px;"&gt;
                                          &lt;/div&gt;
                                          &lt;div class="file-thumbnail-footer"&gt;
                                              &lt;div class="file-actions"&gt;
                                                  &lt;div class="file-footer-buttons"&gt;';
                                                      if ($fila-&gt;active == 1) {
                                                          $output .=  '&lt;a href = "javascript:desactivar(' . $fila-&gt;id_imagen . ');" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Desactivar imagen"&gt;
                                                      &lt;i class = "glyphicon glyphicon-remove text-danger"&gt;&lt;/i&gt;&lt;/a&gt;';
                                                      } else {
                                                          $output .=  '&lt;a id="work" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Activar imagen"&gt;
                                                      &lt;i class = "glyphicon glyphicon-ok text-primary"&gt;&lt;/i&gt;&lt;/a&gt;';
                                                      }
                                                   $output .= '&lt;/div&gt;
                                                  &lt;div class="clearfix"&gt;&lt;/div&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;';
                          $index ++;
              }
              $output .= '&lt;div class="clear"&gt;&lt;/div&gt;';
          } else {
              $output .= '&lt;p&gt;No hay imagenes disponibles para mostrar. Prueba agregando una.&lt;/p&gt;';
          }
          echo json_encode($output);
      }
  </code></pre>
  
  <p>this method is loaded into view</p>
  
  <pre><code>&lt;div id="contenimages" class="col-lg-12" style="text-align: center; display: none"&gt;
                  &lt;a data-toggle="modal" data-target="#events-imagenes"&gt;Ver imagenes&lt;/a&gt;
                  &lt;div class="modal fade col-lg-12" id="events-imagenes"&gt;
                      &lt;div class="modal-dialog" style=" width: 800px !important"&gt;
                          &lt;div class="modal-content"&gt;
                              &lt;div class="modal-header"&gt;
                                  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                              &lt;/div&gt;
                              &lt;div class="modal-body clearfix" style="height: 95%; display: initial"&gt;
                                  &lt;div class=" kv-main"&gt;
                                      &lt;div class="file-input "&gt;
                                          &lt;div class="file-preview"&gt;
                                              &lt;div id="imagenesnaves" class=" clickable" tabindex="-1"&gt;
                                                  &lt;div class="clearfix"&gt;&lt;/div&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="clearfix"&gt;&lt;/div&gt;
                              &lt;div class="modal-footer" style="height: 10%; text-align: center"&gt;
                                  &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!-- /.modal-content --&gt;
                      &lt;/div&gt;&lt;!-- /.modal-dialog --&gt;
                  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>once loaded, each image will have a button either on or off</p>
  
  <pre><code>if ($fila-&gt;active == 1) {
  $output .=  '&lt;a href = "javascript:desactivar(' . $fila-&gt;id_imagen . ');" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Desactivar imagen"&gt;
  &lt;i class = "glyphicon glyphicon-remove text-danger"&gt;&lt;/i&gt;&lt;/a&gt;';
  } else {
  $output .=  '&lt;a id="work" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Activar imagen"&gt;
  &lt;i class = "glyphicon glyphicon-ok text-primary"&gt;&lt;/i&gt;&lt;/a&gt;';
  }
  </code></pre>
  
  <p>and functions are run javascript
  script into the view
      </p>
  
  <pre><code>    function activar(id_imagen) {
          $.ajax({
              type: "POST",
              url: '&lt;?php echo base_url() ?&gt;imagenes/activate',
              data: "id_imagen=" + id_imagen,
              beforeSend: function () {
                  //$('#msgUsuario').html('&lt;span&gt;&lt;/span&gt;');
              },
              success: function (respuesta) {
                  $('#contenedor2').html(respuesta);
              }
          });
      }
      function desactivar(id_imagen) {
          $.ajax({
              type: "POST",
              url: '&lt;?php echo base_url() ?&gt;imagenes/deactivate',
              data: "id_imagen=" + id_imagen,
              beforeSend: function () {
                  //$('#msgUsuario').html('&lt;span&gt;&lt;/span&gt;');
              },
              success: function (respuesta) {
                  $('#contenedor2').html(respuesta);
              }
          });
      }
      function eliminar(id_imagen) {
          $.ajax({
              type: "POST",
              url: '&lt;?php echo base_url() ?&gt;imagenes/eliminar',
              data: "id_imagen=" + id_imagen,
              beforeSend: function () {
                  //$('#msgUsuario').html('&lt;span&gt;&lt;/span&gt;');
              },
              success: function (respuesta) {
                  $('#contenedor2').html(respuesta);
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>but when the modal window is opened, do not run, what would it be?</p>