jQuery Dependent DropDown List – States and Districts

4959 0

$1*/ mo hosting! Get going with GoDaddy!


In this tutorial we are going to see how to change district dropdown list option based on the selected state name.

For Localhost create a database with name demos and import the sql file available inside download package.

       

In this example, we have two dropdown for listing states and districts. On changing states dorpdown values, the corresponding district dropdown values will be loaded dynamically using jQuery AJAX.

HTML Code for state and dsitrict dropdown

Getting States using jQuery AJAX

This script contains function that will be called on changing state dropdown values. It will send AJAX request to a PHP page to get corresponding district dropdown options.

 Read State Database using PHP

This PHP code connects database to retrieve district table values based on the country id passed by jQuery AJAX call.

DBcontroller file(dbcontroller.php)

For Localhost create a database with name demos and import the sql file available inside download package.

       

 

In this article

Join the Conversation



Share