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

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
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!
Reply


Messages In This Thread
RE: Autoload Dropdown With Ajax/Jquery - by RobertSF - 12-27-2015, 02:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB