First Id like to thank everyone for such positive response on my previous question.
Now I got another question I need help with.
I have a dropdown menu with a list of items. The list is generated inside while loop. Here is the code:
$query = "SELECT Key, Short FROM product WHERE Active = 1 OR Short LIKE 'Blue%'";
$run = mysql_query($query) or die(mysql_error());
echo 'Product: <br />';
?>
<select id="select2" name="select2">
<?php
$ids = 0;
echo "<option selected='selected'>-Select product-</option>";
while($rows = mysql_fetch_assoc($run)) {
echo "<option value=$ids>".$rows['Short']."</option>";
$ids++;
}
?>
</select><br /><br />
Now what I need to do is create another dropdown menu below this one and show contracts depending on which option they selected from dropdown menu. Each item they select also have a number called Key. Now inside another table called contracts I have stored all contracts with the same value Key. So...in the second dropdown menu I have to show the contracts based on the key they selected with the item in the first dropdown menu.
I really hope it is clear enough to understand, I am a little confused.
Update: Ok, here is new code:
index.php
$("select#select2").change(function(){
$.ajax({
type: "GET",
url: "process.php",
data: "selected_key=" + $(this).val(),
success: function(result) {
$("select#text2").html(result);
}
});
});
</script>
<select id="text2" name="text2">
</select>
And here is my process.php
<?php ## URL_TO_GET_CONTRACTS_FOR_KEY ##
$selectedKey = $_GET['selected_key'];
$query = "SELECT * FROM contacts WHERE Key = '".$selectedKey."'";
$run = mysql_query($query);
while($row = mysql_fetch_assoc($run)) {
echo "<option value='..'>..</option>";
} ?>
But I cant see anything displayed in my text2 dropdown menu.