In my database I have two related fields. The second field depends on the value selected in the first. The relations are:

The function I use in the form of table "conflictos_1" is:
<!--Aquí el javascript para select dependientes-->
<script type="text/javascript">
$(document).ready(function()
{
$("#conflictos1_id_sector_actividad").change(function()
{
var id_sub = $(this).val();
if(id_sub != '')
{
$.ajax
({
type: "POST",
url: '<?php echo url_for('conflictos/subsector'); ?>'+ '?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("<option value=''>-- No se ha seleccionado subsector --</option>");
}
return false;
});
});
</script>
When I add a new record, everything works fine.
But when I edit a record, the select dependent, does not show "selected" value.
In edit mode, when I look at the field "id_subsector_actividad", the selected value should be, for example, <option value="37 " selected="selected">: This is what I see on my form when I inspect the element created with AJAX's function:
<select name="conflictos1[id_subsector_actividad]" id="conflictos1_id_subsector_actividad">
<option value="29 ">14.1 Meretrices</option>
<option value="30 ">Preparación de alimentos y comedor</option>
<option value="31 ">Seguridad</option>
<option value="37 ">redes sanitarias</option>
</select>
This is what I WANT to see:
<select name="conflictos1[id_subsector_actividad]" id="conflictos1_id_subsector_actividad">
<option value="29 ">14.1 Meretrices</option>
<option value="30 ">Preparación de alimentos y comedor</option>
<option value="31 ">Seguridad</option>
<option value="37 " selected="selected">redes sanitarias</option>
</select>
I use this function to filter records in the table "Subsector_actividad_ta8"(I work with Symfony 1.4 and Doctrine):
public function executeSubsector()
{ $id_sub = $_POST['id_sub'];
$this->subsec= Doctrine_Core::getTable('SubsectorActividadTa8') ->createQuery('a')
->where('a.id_sector = ?', $id_sub)
->execute();
}
My question is: What should I change in the AJAX's function, to display the "selected" value in the second field, when I am editing an existing record?