0

Is there a way in Zend Framework to fill a combobox with values depending on the value chosen in a previous combobox, but on the same page?

In my case I have a combobox for domain and one for specialization. If i choose Informatics in the first combobox (domain), I want to fill the second one with a single specialization - "Informatics". But if I choose Math in the first, I want to fill the second one with two specialization: "Mathematics" and "Mathematics & Informatics".

Thank you! Sorin

  • Have you tried AJAX? when one of the combo boxes changes do an AJAX request to the server and return a json object containing the option for the second combo box. – Songo Apr 05 '12 at 22:20
  • Possible Dupe of [how can i populate the value of dropdownbox while selecting the value of another website in php](http://stackoverflow.com/questions/9546883/how-can-i-populate-the-value-of-dropdownbox-while-selecting-the-value-of-another) – ro ko Apr 06 '12 at 02:04

2 Answers2

0

if you have the data with relationships between domain and specialisation in a database in your server. you can attach a listener on change event to your domain combo box and fill the second combo box accordingly by retrieving specialisations of the selected domain using an ajax post request :

here's an example using jquery :

 $(".domain").change(function()
{
  var domainId=$(this).val();
  var dataString = 'domainId='+ domainId; 

 $.ajax
 ({
   type: "POST",
   url: baseurl+"getSpecialisations", 
   data: dataString,
   cache: false,
   success: function(html)
          {
            $(".specialisation").html(html);
          }
 });
});

and in your controller create an action getSpecialisationsAction that will retrieve your domain's specifications, check here for an example of how to send post request to a zend action .

Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69
0

I've used a very simple solution: I've put the option to choose the domain on one page and the option to choose the specialization on another page, based on the domain chosen.