john_deere Posted May 21, 2013 Share Posted May 21, 2013 Hi Guys, I am trying to create chained dependent drop-downs with the third and final drop-down displaying its results in an html table. This all works fine until the final drop-down, where the variables from the previous two is not passed and instead the option value from select #city is displayed in table. Can anyone suggest what is missing between paper_type.php and paper_customisation.php that is causing this issue? Here is the index.php... <?php require('config.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" > <title>Test Price Page</title> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".product_select").change(function() { var dataString = 'id='+ $(this).val(); $.ajax ({ type: "POST", url: "paper_type.php", data: dataString, cache: false, success: function(html) { $(".paper_type").html(html); } }); }); $('.paper_type').live("change",function(){ var dataString = 'id='+ $(this).val(); $.ajax ({ type: "POST", url: "paper_customisation.php", data: dataString, cache: false, success: function(html) { $(".paper_customisation").html(html); } }); }); }); </script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#city').change(function(){ city_id = $('#city').val(); $.post('paper_customisation.php',{city:city_id},function(res){ $("#result").html(res); }); }); }); </script> <style type="text/css"> body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333; background-color: #FFF; margin: 0px; } #frame1 { background-color: #F7F7F7; margin: 30px auto auto; padding: 10px; width: 700px; } #frame1 label { width:60px; display: inline-block; text-align:right; padding-right:10px; } </style> </head> <body> <div id="frame1"> <label>Product</label> <select name="product_select" class="product_select"> <option selected="selected">--Select Product--</option> <?php $sql=mysql_query("select * from product_id_name order by id ASC"); while($row=mysql_fetch_array($sql)) { echo '<option value="'.$row['id'].'">'.$row['ProductName'].'</option>'; } ?> </select> <label>Paper Type</label> <select name="paper_type" class="paper_type"> <option selected="selected">--Select Paper Type--</option> </select> <label>Flat or Fold</label> <select name="city" id="city"> <option selected="selected">--Select Finish Type--</option> <option value="1">Flat</option> <option value="2">Fold</option> <option value="3">Creased & Fold</option> <option value="4">Creased & Flat</option> </select> <div id="result"> </div></div> </body> </html> And here is paper_type.php... <?php require('config.php'); if($_POST['id']) { $id=$_POST['id']; $sql=mysql_query("select * from paper_type where print_products_id='$id' "); echo '<option selected="selected">--Select Paper Type--</option>'; while($row=mysql_fetch_array($sql)) { echo '<option value="'.$row['id'].'">'.$row['PaperType'].'</option>'; } } ?> Here is the final chained drop-down... <?php $id = $_POST['city']; require('config.php'); //find the record $sql = " select * from northern_prices where finish_type = '".$id."' "; $query = mysql_query($sql); //fetch the results and display in a html table echo "<table border='1'><tr><th>ID</th><th>Name</th><th>City</th></tr>"; while( $row = mysql_fetch_assoc( $query ) ){ echo "<tr><td>$row[id]</td><td>$row[ProductQuantity]</td><td>$row[SingleSided]</td>"; } echo "</table>"; ?> I realise mysql_ is deprecated, but if I can only get the script to work I will endeavour to change that Thank you for any help. Quote Link to comment Share on other sites More sharing options...
john_deere Posted May 21, 2013 Author Share Posted May 21, 2013 please close this post. I have posted twice Quote Link to comment Share on other sites More sharing options...
john_deere Posted May 21, 2013 Author Share Posted May 21, 2013 ok don't close this one, you deleted the other lol Quote Link to comment 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.