Php

Fill Dropdown in PHP using JQuery AJAX



Populating country dropdown through the jQuery ajax() method is a very common implementation of ajax feature that you have seen on many websites while filling the registration form.

Populate Dropdown on the basis of another dropdown value in PHP using JQuery Ajax

Similar Posts

12 thoughts on “Fill Dropdown in PHP using JQuery AJAX
  1. I am not able to retrive the table data someone help me please

    the code is
    Coutry table///country.php
    <?php
    include('connectdb.php');
    ?>
    <html>
    <head>
    <script src="jquery.min.js"></script>
    <script type="text/javascript">
    function County1()
    {
    $('#county').empty();
    $('#county').append("<option>loading…..</option>");
    $.ajax
    ({
    type :"POST",
    url : "dropdown.php",
    content-type : "application/json ; charset=utf-8",
    dataType: "json",
    success : function(data)
    {
    $('#county').empty();
    $('#county').append("<option value = '0'>Select—Expence</option>");
    $.each(data,function(i, item)
    {
    $('#county').append('<option value = "'+data[i].id+'">'+data[i].name+'</option>');
    });
    },
    complete: function(){

    }

    });
    }
    $(document).ready(function()
    {
    County1();
    });

    </script>
    </head>
    <body>
    <select id="county"></select>

    </body>
    </html>

    dropdown.php file
    <?php
    include('connectdb.php');
    $sql = mysql_query('select id, name from emp');
    if(mysql_num_rows($sql))
    {
    $data = array ();
    while($row = mysql_fetch_array($sql))
    {
    $data[] = array('id' => $row['id'], 'name' => $row['name']);
    }
    header ('Content-type: application/json');
    echo json_encode($data);
    }
    ?>

Leave a Reply

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