Posted on Updated on - Arjun

Cascading Dropdown List in CodeIgniter

In this post I will show very simple and powerful approach to create cascading dropdowns in your CodeIgniter application.

Cascading drop-down?

A cascading dropdown list is a series of dependent dropdown list controls in which one dropdown list control depends on the parent or previous dropdown list controls. The items in the dropdown list control are populated based on an item that is selected by the user from another dropdown list control.

Generate Cascading Dropdown List

Cascading Dropdown Example

This example contains two dropdowns, country and state. Based on the country selection the state dropdown list will get updated with appropriate options list.

Follow the below steps to generate depended dropdowns in your CodeIgniter applicaiton-
Step 1: Download and install CodeIgniter.
Step 2: Create a database, to configure database settings update config/database.php file.

Step 3: – We gonna use following tables (country_table, city_table) and its data –

Step 4: Create a custom helper to generate dropdown html. Follow below steps to create DropDown Helper:

  • 1. crate a file called dropdown_helper.php in application/helper/dropdown_helper.php.
  • 2. Then copy paste the following code.

Step 5: Lets open welcome controller and update its index method with below code

Step 6: Now update welcome_message.php view file with below content

Useful links

codeigniter dropdown list from database
CodeIgniter form dropdown Validation?
Html Select Tag

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status