Search the Community
Showing results for tags '#chained'.
-
Hey! Im trying to do a chained select dropdown. 1 dropdown decides what should be shown in the second one...i think you all are familiar with this. Anyway..im following this guide: http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/ But something is wrong, i cant get it to work properly. My first dropdown is populating correct, but the second one is not working. If i choose something in the first dropdown, the second one just stops at "wait...". I think the problem is somewhere in add_project.php, but im not sure. Here is my code: add_project.php: <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("select#category").change(function(){ var id = $("select#category option:selected").attr('value'); $.post("select_type.php", {id:id}, function(data){ $("select#type").html(data); }); }); }); </script> <?php include "select.class.php"; ?> <form id="select_form"> Choose a category:<br /> <select id="category"> <?php echo $opt->ShowCategory(); ?> </select> <br /><br /> choose a type:<br /> <select id="type"> <option value="0">choose...</option> </select> <br /><br /> <input type="submit" value="confirm" /> </form> <div id="result"></div> select.class.php: <?php class SelectList { public function ShowCategory() { $sql = mysql_query("SELECT * FROM `projectCategory`"); // $res = mysql_query($sql,$this->conn); $category = '<option value="0">choose...</option>'; while($row = mysql_fetch_array($sql)) { $category .= '<option value="' . $row['categoryId'] . '">' . $row['categoryName'] . '</option>'; } return $category; } public function ShowType() { $query = mysql_query("SELECT huvudProjectId, huvudProjectName FROM `huvudProject` WHERE `categoryProject` = categoryId=$_POST[id]"); $type = '<option value="0">choose...</option>'; while($row = mysql_fetch_array($query)) { $type .= '<option value="' . $row['huvudProjectId'] . '">' . $row['huvudProjectName'] . '</option>'; } return $type; } } $opt = new SelectList(); ?> select_type.php: <?php include "select.class.php"; echo $opt->ShowType(); ?> Hope someone can help me with this! I've tried SO many hours but I cant find the problem.