title: Symfony 1.4 with AJAX jQuery. How can I improve the AJAX's function that contains a select box which depends on another select box?
body: <p>I use Symfony 1.4. I have three tables related to one another as shown below.</p>
  
  <p>Table 1:</p>
  
  <pre><code>Conflictos1:
    connection: doctrine
    tableName: conflictos_1
    columns:
      id:
        type: integer(4)
        fixed: false
        unsigned: false
        primary: true
        autoincrement: true
  
      id_sector_actividad:
        type: integer(4)
        fixed: false
        unsigned: false
        primary: false
        notnull: true
        autoincrement: false
  
      id_subsector_actividad:
        type: integer(4)
        fixed: false
        unsigned: false
        primary: false
        notnull: false
        autoincrement: false
  
    relations:
  
      SectorActividadCiuTa7:
        local: id_sector_actividad
        foreign: id
        type: one
      SubsectorActividadTa8:
        local: id_subsector_actividad
        foreign: id
        type: one
  </code></pre>
  
  <p>Table 2  and 3:</p>
  
  <pre><code>SectorActividadCiuTa7:
    connection: doctrine
    tableName: sector_actividad_ciu_ta7
    columns:
      id:
        type: integer(4)
        fixed: false
        unsigned: false
        primary: true
        autoincrement: true
      sector_actividad:
        type: string(255)
        fixed: false
        unsigned: false
        primary: false
        notnull: true
        autoincrement: false
    relations:
      Conflictos1:
        local: id
        foreign: id_sector_actividad
        type: many
      SubsectorActividadTa8:
        local: id
        foreign: id_sector
        type: many
  SubsectorActividadTa8:
    connection: doctrine
    tableName: subsector_actividad_ta8
    columns:
      id:
        type: integer(4)
        fixed: false
        unsigned: false
        primary: true
        autoincrement: true
      id_sector:
        type: integer(4)
        fixed: false
        unsigned: false
        primary: false
        notnull: true
        autoincrement: false
      descripcion:
        type: string(255)
        fixed: false
        unsigned: false
        primary: false
        notnull: true
        autoincrement: false
    relations:
      SectorActividadCiuTa7:
        local: id_sector
        foreign: id
        type: one
      Conflictos1:
        local: id
        foreign: id_subsector_actividad
        type: many
  </code></pre>
  
  <p>I have generated with Symfony a module named "conflictos". In this module I have a partial _form.php.This partial contains an AJAX function. Here the code:</p>
  
  <pre><code>&lt;?php use_stylesheets_for_form($form) ?&gt;
  &lt;?php use_javascripts_for_form($form) ?&gt;
  &lt;?php use_helper('Date') ?&gt;
  
  &lt;!--Aquí el javascript para select dependientes--&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function()
  {
      $("#conflictos1_id_sector_actividad").change(function()
      {
          var id_sub = $(this).val();
          if(id_sub != '')
          {
              $.ajax
              ({
                  type: "POST",
                  url: '&lt;?php echo url_for('conflictos/subsector'); ?&gt;'+ '?id=' + id_sub,
                  cache: false,
                  data: "id_sub="+ id_sub,
                  success: function(data)
                  {
                      $("#conflictos1_id_subsector_actividad").html(data); // but it does not select the value of dropdown list.
                  }
              });
          }
          else
          {
              $("#conflictos1_id_subsector_actividad").html("&lt;option value=''&gt;-- No se ha seleccionado subsector --&lt;/option&gt;");
          }
          return false;
      });
  });
  &lt;/script&gt;
  &lt;form action="&lt;?php echo url_for('conflictos/'.($form-&gt;getObject()-&gt;isNew() ? 'create' : 'update').(!$form-&gt;getObject()-&gt;isNew() ? '?id='.$form-&gt;getObject()-&gt;getId() : '')) ?&gt;" method="post" &lt;?php $form-&gt;isMultipart() and print 'enctype="multipart/form-data" ' ?&gt;&gt;
      &lt;?php if (!$form-&gt;getObject()-&gt;isNew()): ?&gt;
          &lt;input type="hidden" name="sf_method" value="put" /&gt;
      &lt;?php endif; ?&gt;
      &lt;table border="0" width="96%"&gt;
          &lt;tfoot&gt;
              &lt;tr&gt;
                  &lt;td align="center" colspan="4"&gt;
                      &lt;?php echo $form-&gt;renderHiddenFields(false) ?&gt;
                      &amp;nbsp;&lt;a href="&lt;?php echo url_for('conflictos/index') ?&gt;"&gt;&lt;button class="btn btn-success" type="button"&gt;Listado&lt;/button&gt;&lt;/a&gt;
                      &lt;?php if (!$form-&gt;getObject()-&gt;isNew()): ?&gt;
                          &amp;nbsp;&lt;?php echo link_to('&lt;button class="btn btn-danger" type="button"&gt;Borrar&lt;/button&gt;', 'conflictos/delete?id='.$form-&gt;getObject()-&gt;getId(), array('method' =&gt; 'delete', 'confirm' =&gt; '¿Está seguro?')) ?&gt;
                      &lt;?php endif; ?&gt;
                      &lt;!--&lt;input type="submit" value="Save" /&gt;--&gt;
                      &lt;button class="btn btn-primary" type="submit"&gt;Grabar&lt;/button&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tfoot&gt;
          &lt;tbody&gt;
              &lt;?php echo $form-&gt;renderGlobalErrors() ?&gt;
              &lt;tr&gt;
                  &lt;td  width="24%"&gt;&lt;?php echo "&lt;b&gt;Sector Actividad &lt;font color='red'&gt; (*)&lt;/b&gt;&lt;/font&gt;&lt;br&gt;"  ?&gt;
                      &lt;?php echo $form['id_sector_actividad']-&gt;renderError() ?&gt;
                      &lt;?php echo $form['id_sector_actividad'] ?&gt;
                  &lt;/td&gt;
                  &lt;td  width="24%"&gt;&lt;?php echo "&lt;b&gt;Subsector Actividad&lt;/b&gt;&lt;br&gt; "  ?&gt;
                      &lt;?php echo $form['id_subsector_actividad']-&gt;renderError() ?&gt;
                      &lt;select name="conflictos1[id_subsector_actividad]" id="conflictos1_id_subsector_actividad"&gt;
                          &lt;option value="" selected="selected"&gt;Seleccione sub-sector&lt;/option&gt;
                  &lt;/td&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The AJAX function works fine when I add a new record, but when I want to edit a record, the field corresponding to select id_subsector_actividad appears empty.</p>
  
  <p>My question is: What should I change in the AJAX function, to display the field value "id_subsector_actividad", when I call the function executeEdit with Symfony?</p>