Repopulate Autoload Dropdown value With Ajax/Jquery - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Repopulate Autoload Dropdown value With Ajax/Jquery (/showthread.php?tid=63955) |
Repopulate Autoload Dropdown value With Ajax/Jquery - Codeigniter_Learner - 12-27-2015 I have spent 2 days on this and I am reaching nowhere. I am a new learner and as encouraged by forum members in one of my other post I am using this forum to get hand on CI. I am new to php and CI. I have this strange problem here. I am able to repopulate dropdown field value upon error on the first dropdown field only because the values for first field are being pulled from "view.php". I also posted this question on stackoverflow but no response Link Here I have model: Code: function getCountry(){ And a controller dashboard.php Code: public function loadData() And View: Code: <?php if($list->num_rows() > 0){ ?> And I am totaly lost about ajax.jquery. PLEASE HELP! RE: Autoload Dropdown With Ajax/Jquery - RobertSF - 12-27-2015 You want the value selected in one dropdown to limit the choices offered in the other dropdown, so if you select Northern region, for example, the other dropdown shouldn't include cities in Texas and Arizona. Most of the action happens in Javascript, not PHP. I don't know much Javascript (which is what JQuery and Ajax are, basically), so I can't show you specific code, but the general idea is this. 1.- In your controller, load the data for both dropdowns into respective PHP arrays. 2.- Format the data for each dropdown into a string that can be inserted into your Javascript code. See the PHP docs for implode. Code: In PHP: It's not a tutorial, but stackoverflow.com usually has some good answers. This may work. http://stackoverflow.com/questions/20483470/javascript-dynamic-drop-down-menu-values RE: Autoload Dropdown With Ajax/Jquery - John_Betong - 12-27-2015 This tutorial may be of interest. http://www.johns-jokes.com/downloads/sp-e/jb-ajax-search/ RE: Autoload Dropdown With Ajax/Jquery - Codeigniter_Learner - 12-30-2015 (12-27-2015, 02:20 PM)RobertSF Wrote: You want the value selected in one dropdown to limit the choices offered in the other dropdown, so if you select Northern region, for example, the other dropdown shouldn't include cities in Texas and Arizona. Most of the action happens in Javascript, not PHP. I don't know much Javascript (which is what JQuery and Ajax are, basically), so I can't show you specific code, but the general idea is this. Hi thanks for your reply. I somehow figured out to make dropdown work but they don't repopulate upon error. I posted it on stachoverflow nut no response. Link RE: Autoload Dropdown With Ajax/Jquery - Codeigniter_Learner - 12-30-2015 (12-27-2015, 05:34 PM)John_Betong Wrote: This tutorial may be of interest. Thanks John. I got it working now. Do you have any idea about how to repopulate dropdown fields upon error? Here is my post on StackOverFlow. RE: Repopulate Autoload Dropdown value With Ajax/Jquery - RobertSF - 12-30-2015 If you mean to repopulate after CI form validation fails, check this out. https://www.codeigniter.com/user_guide/libraries/form_validation.html?highlight=error#re-populating-the-form |