Update Dropdown Options based on User Input in View |
Hi, I want to update the <option> of dropdown input from a database, based on user input. Here my table structure:
I have two tables namely 'district' and 'city' STRUCTURE OF 'district' TABLE: id name active 1 ABC 1 2 XYZ 2 STRUCTURE OF 'city' TABLE: id name[b] district active[/b] 1 DEFG 1 1 2 IJKL 1 1 2 MNOP 2 1 2 QRST 2 1 I want to update 'city' select <option> in view to be updated based on the <option> selected for 'district' <select> dropdown. Here is method responsible for view. CODE OF METHOD Code: public function edit($id = NULL) CODE OF VIEW Code: <select name="district" required> In the above code the data data from database has been updated in <select> dropdown options for both district and city. But I want cities name based on selected district to be updated in city <select> dropdown options. PLEASE HELP
You will need to use javascript to do this, here is the link to one.
Update Dropdown Listbox PHP Way: PHP Dropdown Listbox What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(03-17-2016, 04:06 AM)InsiteFX Wrote: You will need to use javascript to do this, here is the link to one. Thanks for reply, I have tried to get the same through jquery, but I didn' get the result here is my code: Here is my View: Code: <option value='' selected>--Select--</option> JAVASCRIPT: Code: <script> CONTROLLER: Code: class Check extends Admin_Controller { MODEL: Code: public function get_city($where){ Kindly help me? and tell me where I am doing wrong. Thanks.
Should be:
Code: <select name="city" id="city"></select> You also need to create the second select listbox. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |