Jump to content

Recommended Posts

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...

 

 

Link to comment
https://forums.phpfreaks.com/topic/260656-loading-db-info-dropdown-list/
Share on other sites

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.