Hi. I have one drop down menu and one textfield. The drop down menu will display the book's id and book's name that retrieve from the database while the textfield will automatically display the book's name based on the user selection from the drop down menu. I try to use the javascript function to do this but since the value for the option is book's id so the textfield is displayed the book's id but not the book's name. What should I do so that the textfield will display the book's name? Below are parts of the code.
<?php $sql = "SELECT * FROM store ORDER BY book_id";
$result = mysql_query($sql);
?>
<select name="book_id" id="book_id" class="font" onChange="updateText();"><option value=""></option>
<?php while($row = mysql_fetch_array($result))
{ ?>
<option value="<?php echo $row['book_id']; ?>" class="font"><?php echo $row['book_id']; ?> <?php echo $row['book_name']; ?></option>
<?php }?>
</select>
<input type="text" name="book_name" id="book_name" class="font" readonly="readonly">
javascript code:
<script type="text/javascript">
function updateText()
{
document.getElementById("book_name").value = document.getElementById("book_id").value;
}
</script>
Thanks in advance.