How to Fill Dropdown with Non Ajax

In This simple PHP tutorial, I will let you know how to fill dropdown with non ajax manner. Normally we are refreshing dropdown based on selected master dropdown value, i.e we are using country and states two dropdown and based on country selected we will fill state dropdown. There are two method one is – we can fire a Ajax request based on selected country and other is we can set state using json object without ajax round-trip. This can improve your website response time. Here we will learn that.


Also Checkout other Dropdown jQuery tutorial,

Below are simple steps to filled dropdown values with non ajax method:

Steps 1: We will get all necessary data from both dropdown based on our requirement.
Steps 2: We will convert that array into json object.

Steps 3: We will create HTML Layout.

Steps 4: We will iterate on json object and append to state dropdown list.

Live Demo and Download Source Code

3 thoughts on “How to Fill Dropdown with Non Ajax

  1. thank you very much for this post:D,, but can you please one more field “CITY” with drop down in above post??
    Help me please..Thanks in Advance!!!

    • Hi Ganagn,

      This is solution as per your requirement.

      define php array:

      $city = array(

      ‘DL’ => array(‘SD’ => ‘South DElhi’,

      ‘ND’ => ‘North Delhi’),

      ‘UP’ => array(‘LKO’ => ‘Lucknow’,

      ‘NO’ => ‘NOIDA’)


      Assigned data to json object:

      var _cityData = {};

      var _cityData = ;

      html code:

      — Select City —

      jquery code:

      doc.delegate(‘.state-select’, ‘change’, function(e){

      var source = $(this),

      val = $.trim(source.val()),

      target = source.attr(‘target’);


      if(typeof(_cityData[val]) != “undefined”){

      var options = (typeof(_cityData[val]) != “undefined”) ? _cityData[val] : {};

      $(‘– Select City –‘).appendTo(target);

      $.each( options , function(value, index) {

      $(” + index + ”).appendTo(target);




Leave a Reply

Your email address will not be published. Required fields are marked *