Jump to content

Recommended Posts

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="

Link to comment
https://forums.phpfreaks.com/topic/272912-chained-listboxs-not-updating/
Share on other sites

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));

});

 

});

:code_tags: , 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.

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 by DSTR3

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.