DSTR3 Posted January 9, 2013 Share Posted January 9, 2013 I have a series of three listboxes. The first one is working, however the next two refuse to update after clicking on the first one! My table structure is as follows. tblRestaurants RestID, RestName, RestStatus tblLocations RestID, LocationID, CityID, AreaID tblCities CityID, CityName tblAreas AreaID, AreaName The first listbox gives the restaurants, the second the given city(s) that they are in, and third the Area(s) of the city they are in. Here is the main page..... index.PHP <?php try { $objDb = new PDO('mysql:host=MyHead.db.5513143.hostedresource.com;dbname=MyHead', 'MyHead', 'MenuHead@1234'); $objDb->exec('SET CHARACTER SET utf8'); $sql = "SELECT * FROM `tblRestaurants` WHERE `RestStatus` = 'YES' ORDER BY 'RestName'"; $statement = $objDb->query($sql); $list = $statement->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { echo 'There was a problem'; }<p>?> <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8" /> <title>Dependable dropdown menu</title> <meta name="description" content="Dependable dropdown menu" /> <meta name="keywords" content="Dependable dropdown menu" /> <link href="/BigStuff/css/core.css" rel="stylesheet" type="text/css" /> <!--[if lt IE 9]> <script src=" Quote Link to comment https://forums.phpfreaks.com/topic/272912-chained-listboxs-not-updating/ Share on other sites More sharing options...
DSTR3 Posted January 9, 2013 Author Share Posted January 9, 2013 Oooops. Forgot to add this! core.js var formObject = { run : function(obj) { //if (obj.val() === '') { obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true); //} else { var id = obj.attr('id'); var v = obj.val(); jQuery.getJSON('/BigStuff/mod/update.php', { RestID : RestID, value : v }, function(data) { if (!data.error) { obj.next('.update').html(data.list).removeAttr('disabled'); } else { obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true); } }); //} } }; $(function() { $('.update').live('change', function() { formObject.run($(this)); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/272912-chained-listboxs-not-updating/#findComment-1404502 Share on other sites More sharing options...
cpd Posted January 9, 2013 Share Posted January 9, 2013 , is it really that hard? The code in the OP is completely useless as we've no idea how you've used $list and we can't see your HTML which could be the problem. Echoing "There was a problem" before the body tags is really bad control flow as well. Re-think how you display errors. Quote Link to comment https://forums.phpfreaks.com/topic/272912-chained-listboxs-not-updating/#findComment-1404510 Share on other sites More sharing options...
DSTR3 Posted January 9, 2013 Author Share Posted January 9, 2013 (edited) Thank you for your response. Since I am completely new to all of this, I don't quite understand what you mean about $list. I see what you mean, It was cut off! Adding it here. Also where would I place the ERROR? <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8" /> <title>Dependable dropdown menu</title> <meta name="description" content="Dependable dropdown menu" /> <meta name="keywords" content="Dependable dropdown menu" /> <link href="/BigStuff/css/core.css" rel="stylesheet" type="text/css" /> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div id="wrapper"> <div align="center"> <select name="Place" size="25" id='Place' class="update"> <option value="">Select one</option> <?php if (!empty($list)) { ?> <?php foreach($list as $row) { ?> <option value="<?php echo $row['RestID']; ?>"> <?php echo $row['RestName']; ?> </option> <?php } ?> <?php } ?> </select> <select name="City" size = "25" id="City" class="update" disabled="disabled"> <option value="">----</option> </select> <select name="Area" size="25" id="Area" class="update" disabled="disabled"> <option value="">----</option> </select> </div> </form> </div> <script src="/BigStuff/js/jquery-1.6.4.min.js" type="text/javascript"></script> <script src="/BigStuff/js/core.js" type="text/javascript"></script> </body> </html> Edited January 9, 2013 by DSTR3 Quote Link to comment https://forums.phpfreaks.com/topic/272912-chained-listboxs-not-updating/#findComment-1404511 Share on other sites More sharing options...
DSTR3 Posted January 10, 2013 Author Share Posted January 10, 2013 After giving it much thought, the problem is that all of the examples that I am finding either use one table or no tables. My first box has one table. tblRestaurants. The second box has two tables tblLocations and tblCities, joined at the CityID field. The third listbox has once again tblLocations and tblAreas, joined on the AreaID field. I hope this clarifies things a bit! Quote Link to comment https://forums.phpfreaks.com/topic/272912-chained-listboxs-not-updating/#findComment-1404522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.