symfony - populating multiple drop down select lists (AJAX) - UPDATED
I have a form, with 2 fields, that are select lists.
I need to se开发者_高级运维lect 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.
精彩评论