简体   繁体   中英

symfony - populating multiple drop down select lists (AJAX) - UPDATED

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM