Table book
contains: book_id
,book_title
Table bookext
contains: bookext_id
,book_id
(foreigned key to book
),bookext_tag
Here is my script where i want to populate my dropdown is.
<script>
function get_bookextt() {
var request = $.ajax({
url: "getbookext.php",
type: "POST",
dataType: "html"
});
request.done(function(msg) {
$("#get_bookext").html(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
}
</script>
Seeing that code, here is the body part for my first dropdown that will associate the second dropdown that must appear
<select id="book" name='book' onchange="get_bookextt();">
<option value=''>Select</option>
<?php while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['book_id'] . "'>" . $row['book_title'] . "</option>";}
?>
</select>
<div id="get_bookext"></div>
I really feel dumb for posting my whole getbookext.php file in here because I think this is where I messed up.
<?php
include 'db_connection.php';
if ($_POST) {
$book_id = $_POST['book_id'];
if ($book_id != '') {
$sql1 = "SELECT * FROM bookext WHERE book_id=" . $book_id;
$result1 = mysql_query($sql1);
echo "<select name='bookext'>";
echo "<option value=''>Select</option>";
while ($row = mysql_fetch_array($result1)) {
echo "<option value='" . $row['bookext_id'] . "'>" . $row['bookext_tag'] . "</option>";}
echo "</select>";
}
else
{
echo '';
}
}
?>
Please pinpoint to me where did I go wrong.
--EDITED--
Here is my whole head area
include 'db_connection.php';
$sql = "SELECT * FROM book";
$result = mysql_query($sql);
?>
<script>
function get_bookextt() {
var request = $.ajax({
url: "getbookext.php",
type: "POST",
data: {'book_id', $(this).val()},
dataType: "html"
});
request.done(function(msg) {
$("#get_bookext").html(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
}
</script>
Whilst here is the whole body area
<select id="book" name='book' onchange="get_bookextt($(this).val());">
<option value=''>Select</option>
<?php while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['book_id'] . "'>" . $row['book_title'] . "</option>";}
?>
</select>
<div id="get_bookext"></div> // Sub will be appended here using ajax
PS1. I don't understand why get_bookextt($(this).val());
isn't highlighting in my notepad++.