Multiple Dropdown Lists Using jQuery Ajax and PHP

In this tutorial we will populate a dropdown list based on the value of another dropdown list. This is commonly used for countries and states.

Want to Learn More?

Become a member and get access to the member only area of this site.

LEARN MORE

Comments

Your email address will not be published.

User Avatar

A comprehensive tutorial. Thanks very much!

by JD, 06-Jan-2016

User Avatar

is it possible when you click 'state' a company details is displayed from "company" table

by Gautam Bose, 20-Jul-2016

User Avatar

@Gautam Yes, it is possible to do this. You would just need to add another level to the drop downs. The code would be similar to getStates.php

by Patrick Morrow, 22-Jul-2016

User Avatar

can you please show me your tables

by Mangen, 08-Apr-2017

User Avatar

@Mangen - if you look at STEP 1 you will see the table structure. They are very basic tables. If you look at the end of the step you will also see a link to a SQL dump of the tables which you could then upload to your own server.

by Patrick Morrow, 10-Apr-2017

User Avatar

sir can you share the connection part using object oriented or procedural instead of pdo

by mangen, 10-Apr-2017

User Avatar

@mangen - I highly recommend that you use a PDO connection. However, the MySQLi connection would look something like this:

$db_host = "localhost";
$db_username = "username";
$db_password = "password";
$db = mysqli_connect($db_host, $db_username, $db_password);

You can obviously then test for a successful connection etc.

by Patrick Morrow, 13-Apr-2017

User Avatar

thank you sir, your code is very helpful

by Mangen, 13-Apr-2017

User Avatar

sir i'm new to php would you show me how proper validation is done both from the front and back end

by mangen, 15-Apr-2017

User Avatar

@Mangen what do you mean by proper validation? Do you mean how to validate an input e.g. to check if an email address is actually an email address OR do you mean to validate for security?

by Patrick Morrow, 16-Apr-2017

User Avatar

do you have a video tutorial on this as it would be nice to hear your explanations

by Laurent, 10-Jul-2018

User Avatar

Yes, there is a video as part of the membership package

by Patrick Morrow, 11-Jul-2018

PHP for Beginners

Would you like lifetime access to the hugely successful PHP for Beginners course? Click here to find out how.

FREE Code Snippets

FREE hints and tips delivered direct to you once per month.