Repopulate Autoload Dropdown value With Ajax/Jquery |
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!
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/20483...enu-values
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
(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
(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.
If you mean to repopulate after CI form validation fails, check this out.
https://www.codeigniter.com/user_guide/l...g-the-form
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
|
Welcome Guest, Not a member yet? Register Sign In |