Welcome Guest, Not a member yet? Register   Sign In
Repopulate Autoload Dropdown value With Ajax/Jquery
#4

(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.

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:
$region_list = '"' . implode('", ', $regions) . '"';

In your Javascript code:
var regions = {<?php echo $region_list ?>};
3.- Your Javascript code should be triggered on change by the first dropdown, and from the value in the first dropdown, it should then load the correct options into the second dropdown.

It's not a tutorial, but stackoverflow.com usually has some good answers. This may work.
http://stackoverflow.com/questions/20483...enu-values

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
Reply


Messages In This Thread
RE: Autoload Dropdown With Ajax/Jquery - by Codeigniter_Learner - 12-30-2015, 02:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB