CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Adding a second Value to Pass On (http://www.codingforums.com/showthread.php?t=285992)

DS928 01-18-2013 06:36 AM

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>';
}
}

?>



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

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.