0

I have a form, with 2 fields, that are select lists.

I need to select an option from select_list_1 that then populates select_list_2

I have the following in my template:

<script type="text/javascript">
$(document).ready(function() {
  $('select#sf_guard_user_profile_corp_id').change(function() {
    $.ajax({
      url: "updateAreaManager?corp_id=" + this.value,
      dataType: "text/html",
      success: (function(data) {
        $('select#sf_guard_user_profile_area_manager_id').html(data);
      })
    });
  });
});
</script>

This calls the executeUpdateAreaManager method, which currently is simply:

public function executeUpdateAreaManager(sfWebRequest $request)
{
   $id = $request->getParameter('corp_id');
}

Would someone be able to help me get the data I need into the second select list?

Thanks

jgallant
  • 11,143
  • 1
  • 38
  • 72
sipher_z
  • 1,221
  • 7
  • 25
  • 48

1 Answers1

0

I am guessing that since you have a corp_id being passed to your action, you are trying to get a list of Managers based on a corp_id value.

In your action, you can query your database in order to get a result set, by doing something like:

$q = Doctrine_Query::create()->from('Manager m')->innerJoin('m.Corps c')->where('c.id=', $id);
$results = $q->execute();

You then can pass the results to your javascript, whatever way you want. I suggest straight HTML at this point. Your code will ressemble something like this (still in your action.class.php file):

echo "<p>Hi, I came from an action.</p>";
return true; 

At this point, your javascript should be displaying that HTML on your page. Make it generate what you n eed, assuming an HTML form in your case.

jgallant
  • 11,143
  • 1
  • 38
  • 72
  • My main problem is passing the values into the second select list, since the template is a `_form.php` partial. – sipher_z Apr 28 '11 at 08:02
  • Does anyone know how I'd pass the values back to the `_form.php` partial and populate the second drop down? – sipher_z Apr 28 '11 at 12:47