0
votes

I am using zend framework and want to create a zend form where the user selects (using dropdowns) a country. Depending on the country, I would like the second 'region' dropdown to populate with the appropriate regions. Again, depending on the selected region, I would like a dropdown of cities to be populated. In each case, until the preceding values has been selected, I would like the next dropdown to be empty. I am using doctrine2 and want these to be populated from the db.

What would be the best way to achieve this?

1

1 Answers

1
votes

I don't think there is any native way to achieve this using Zend framework. But you can use AJAX to send a request to the server when the user changes the option in the first select box and update the second select box with the results from the AJAX call.

$("#item_select_1").change(function()
{
  $.getJSON("/select.php",{id: $(this).val(), ajax: 'true'}, function(j){
  var options = '';
  for (var i = 0; i < j.length; i++) {
    options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
  }
  $("#item_select_2").html(options);
});

}

For the server side code, http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/