Pain Posted April 10, 2012 Share Posted April 10, 2012 Hey there. I have this drop down list on main.php <form method="POST"> <p><select name="how_old"></p> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> </select> <p><select name="how_old2"></p> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> </select> <input type="submit" name="submit" onsubmit="loadXML"/> </form> When i pick an option, i want search.php to be loaded with ajax. <?php session_start(); require("functions.php"); // mysql query $query2 = mysql_query("SELECT * FROM members ORDER BY date_joined DESC LIMIT 8"); $how_old = $_POST['how_old']; $how_old2 = $_POST['how_old2']; ?> <?php $query = mysql_query("SELECT * FROM members WHERE age >= '$how_old' AND age <= '$how_old2'"); while ($row = mysql_fetch_assoc($query)) { $username = $row['username']; $age = $row['age']; $profile_picture = $row['image']; $id = $row['id']; echo "<p><a href='user_profile.php?id=$id'><img src='$profile_picture' style='border:1px solid black' height='45' width='45' /></a></p>"; echo '<p>' . $username . '</p>'; echo '<p>' . $age . '</p><br />'; } ?> </body> </html> Usually i use action in my form and process all the code in another page. However i am not sure how to do it with ajax... Quote Link to comment https://forums.phpfreaks.com/topic/260656-loading-db-info-dropdown-list/ Share on other sites More sharing options...
caliux Posted April 10, 2012 Share Posted April 10, 2012 You can use a jQuery event $('#list').change(function(){ your ajax function}); Quote Link to comment https://forums.phpfreaks.com/topic/260656-loading-db-info-dropdown-list/#findComment-1335969 Share on other sites More sharing options...
Pain Posted April 11, 2012 Author Share Posted April 11, 2012 Ammm ok i tried this, but simply nothing happens. I've included the jquery function and also added a class to the selection. <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> function loadXML() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest; } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("search").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","search.php",true); xmlhttp.send(); } $(".list").change(function(){ loadXML(); }); </script> </head> <body> <form method="POST"> <p><select name="how_old" class="list"></p> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> </select> <p><select name="how_old2" class="list"></p> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> </select> <input type="submit" name="submit"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/260656-loading-db-info-dropdown-list/#findComment-1336534 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.