stirrah Posted November 8, 2013 Share Posted November 8, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283722-problem-with-chained-select/ Share on other sites More sharing options...
trq Posted November 8, 2013 Share Posted November 8, 2013 What have you done to debug the issue? Quote Link to comment https://forums.phpfreaks.com/topic/283722-problem-with-chained-select/#findComment-1457526 Share on other sites More sharing options...
stirrah Posted November 8, 2013 Author Share Posted November 8, 2013 (edited) I know that the query is OK, because i've run the method outside and it works. The second dropdown gets populated correctly. So the problem should be in the jquery-code i guess. For me, it seems that the method never gets exececuted. Edited November 8, 2013 by stirrah Quote Link to comment https://forums.phpfreaks.com/topic/283722-problem-with-chained-select/#findComment-1457528 Share on other sites More sharing options...
trq Posted November 8, 2013 Share Posted November 8, 2013 So the problem should be in the jquery-code i guess. So why would you post your question in the "PHP Applications" board? A board designed for questions relating to applications built with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/283722-problem-with-chained-select/#findComment-1457532 Share on other sites More sharing options...
stirrah Posted November 8, 2013 Author Share Posted November 8, 2013 So why would you post your question in the "PHP Applications" board? A board designed for questions relating to applications built with PHP? Oh...I'm so sorry, lol. Im so used to browse this forum...is it possible to move this thread or should a make another one? Quote Link to comment https://forums.phpfreaks.com/topic/283722-problem-with-chained-select/#findComment-1457543 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.