In this post, I will show very simple and powerful approach to create cascading dropdowns in your CodeIgniter application.
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.
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
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
- 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
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.