I have an an html form with only <select> element. Below the form I have a text box, I want to update the value of the text box based on the option selected in the form.
I am not sure if this is possible in PHP, I know I can do it with Javascript/Jquery, but I am working on a school project and its a PHP project. My teacher has done it but Im not sure if he used PHP.
Here is my code:
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="books">
<?php
$books = simplexml_load_file("books.xml");
foreach($books->book as $book){
$code = $book->code;
$title = $book->title;
echo "<option value='$code'>$code: $title</option>";
}
?>
</select>
</form>
<?php
$choice = $_POST['books'];
echo "<input type='text' value='$choice'>";
?>
When the page first loads I want the value from the selected option to be in the text box. I am not sure how I could go about doing this in PHP. Help would be appreciated.