我使用select
表单元素呈现多个选项,然后使用onchange
事件显示文本区域中数据库的相应文本。
select
选项的值非常长,因此我希望将该选项的id
或name
传递给我的表单目标favorite.php,但我不知道该怎么做。
HTML:
<div class="container">
<div class="had">
<form name="det" action="vispage.php" method="POST">
<label for="hadeath">Selct Title of the Hadeath</label>
<select name="header" onchange="document.getElementById('txt').innerHTML=this.value">
<?php foreach($hadeeth as $i) {?>
<option id="<?php echo $i['id']; ?>" value="<?php echo $i['short']; ?>"><?php echo $i['name']; ?></option>
<?php } ?>
</select><br><br>
<label for="a">tree :</label><br>
<textarea id="txt" name="tree" rows="15" cols="30"></textarea><br><br>
<a href="favorite.php" style=" width: 100px; padding:10px; " id="idd" class="btn" role="button">Add to Favorites </a> </form>
</div>
</div>
PHP:
<?php
$title = "hadeeth";
include_once ("header.php");
include 'connect.php';
//CREATE THE QUERY
$query = "SELECT * FROM `search`";
//RUN THE QUERY
$result = mysqli_query($con,$query);
$hadeeth = array();
// RETRIEVE VALUES FROM RESULT
while($row = mysqli_fetch_assoc($result))
{
$hadeeth[$row['name']] = array(
'id'=>$row['id'],
'name'=>$row['name'],
'short'=>$row['short']
);
}
?>