Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 07:39 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •