Solved

Dynamic Dependent select box

Posted on 2014-03-03
3
1,639 Views
Last Modified: 2014-03-03
I'm trying to build a test case of a dynamic dependent select box using mysql/php, ajax, jquery.   Should be streight forward but I having problems.

Here is the test page:

<!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=utf-8" />
<title>Untitled Document</title>

	  	<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
		<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
   
      	<script type="text/javascript">
           $(document).ready(function(){             
               $("#depth").change(function(){
                     var depth=$("#depth").val();
                     $.ajax({
                        type:"post",
                        url:"support_get.php",
                        data:"depth="+depth,
                        success:function(data){
                              $("#Sup_lft").html(data);
                        }	
                     });		
               });
           });
      </script>
</head>
<body>

Depth :
        <select name="depth" id="depth">    
        <?php
        include "support_db.php";
		
        $result=mysql_query("SELECT Category,Series,Glass_Support,Finish,Key_2 FROM Form_Content WHERE Category='Depth' and Series='CRY140-2'");
		 while($depth=mysql_fetch_array($result)){
        	echo "<option value=$depth[Key_2]>$depth[Finish]</option>";
        } ?>
        </select>
         
 
        Support :
        <select name="Sup_lft" id="Sup_Lft">
            <option>-select Support-</option>
        </select>
        
        
</body>
</html>

**********************  support_get.php  *****************
<?php
  include "support_db.php";
 
 $depth=$_POST["depth"];
  $result=mysql_query("select Display_Name,Key_3 FROM Products where Pri_Group = 'CRY140' AND Sec_Group='Lft' AND Key_2='$depth'");
  while($Sup_lft=mysql_fetch_array($result)){
echo"<option value=$Sup_lft[Key_3]>$Sup_lft[Display_Name]</option>";

  }
?>

Open in new window

The include "support_db.php"  and mysql/php access seems to be working.  I have verified that the mysql data is in place. The first select box is functioning.  The Ajax fetch doesn't populate the second select box.   I hope someone will be able to easily point out what I have wrong.

Thanks
0
Comment
Question by:jws2bay
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
$("#Sup_lft").html(data);

should be

$("#Sup_Lft").html(data);

Notice the case
0
 

Author Comment

by:jws2bay
Comment Utility
Don't you hate that.   I changed the id to Sup_lft and all is good.

Thanks for giving it a quick look.
0
 

Author Closing Comment

by:jws2bay
Comment Utility
Correct answer and quick
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now