Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2013, 06:36 AM   PM User | #1
DS928
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
DS928 is an unknown quantity at this point
Adding a second Value to Pass On

I have code that is working. However the problem is that it is only passing one value from one dependent listbox to another. The value is RestID from the tblLoacations table. I also need the CityID from the same table. The current value is named Lid. How would I add this to may already working code. The first part.

Code:
$(document).ready(function()
{
	
$(".Doggie").change(function()
{
	var LocationString = 'Lid='+ $(this).val();
	    $.ajax({
        type: "POST",
        url: "ajax_city.php",
        data: LocationString,
		cache: false,
        success: function (html) {
            $(".Kitty").html(html);
        }
    });
});

$('.Kitty').live("change",function(){
	var LocationString = 'Lid='+ $(this).val();
	    $.ajax({
        type: "POST",
        url: "ajax_area.php",
        data: LocationString,
        cache: false,
        success: function (html) {									   
$(".Pig").html(html);
} 
});

});



});
</script>
</head>
<body>


		<div id="frame1">
  		<label>Place :</label>
  		<select name="Doggie" class="Doggie" id="Doggie">
    	<option selected="selected">--Select Place--</option>
    	<?php
				$sql = mysql_query("SELECT tblLocations.RestID as Lid, tblRestaurants.RestName as name
			FROM tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
			GROUP BY tblLocations.RestID, tblRestaurants.RestName
			ORDER BY tblRestaurants.RestName ASC");
		while($row=mysql_fetch_array($sql))
		{
		echo '<option value="'.$row['Lid'].'">'.$row['name'].'</option>';
				} ?>
 		 </select>
  		<label>City :</label>
  		<select name="Kitty" class="Kitty" id="Kitty">
    	<option selected="selected">--Select City--</option>
  		</select>
  		<label>Area: :</label>
  		<select name="Pig" class="Pig" id="Pig">
    	<option selected="selected">--Select Area--</option>
  		</select>
		</div>
       
</body>
</html>
And one of the PHP files. ajax_city.php

PHP Code:
<?php
require('config.php');

if(
$_POST['Lid'])
{
$Lid=$_POST['Lid'];
$sql=mysql_query("SELECT tblLocations.RestId as Lid, tblCities.CityName as name
                FROM tblLocations INNER JOIN tblCities ON tblLocations.CityID = tblCities.CityID
                WHERE tblLocations.RestID = $Lid
                GROUP BY tblLocations.RestID, tblCities.CityName
                ORDER BY tblCities.CityName ASC"
);
echo 
'<option selected="selected">--Select City--</option>';
while(
$row=mysql_fetch_array($sql))
{
echo 
'<option value="'.$row['Lid'].'">'.$row['name'].'</option>';
}
}

?>
And the other. ajax_area.php

PHP Code:

<?php
require('config.php');

if(
$_POST['Lid'])
{
$Lid=$_POST['Lid'];


$sql=mysql_query("SELECT tblLocations.RestID as LID, tblAreas.AreaName as name
                FROM tblLocations INNER JOIN tblAreas ON tblLocations.AreaID = tblAreas.AreaID
                WHERE tblLocations.RestID = $Lid
                GROUP BY tblLocations.RestID, tblAreas.AreaName
                ORDER BY tblAreas.AreaName ASC"
);

echo 
'<option selected="selected">--Select Area--</option>';
while(
$row=mysql_fetch_array($sql))
{
echo 
'<option value="'.$row['Lid'].'">'.$row['name'].'</option>';
}
}

?>

Last edited by DS928; 01-18-2013 at 06:39 AM..
DS928 is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:28 AM.


Advertisement
Log in to turn off these ads.