Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将选项id从select元素传递到表单提交_Javascript_Php_Html - Fatal编程技术网

Javascript 将选项id从select元素传递到表单提交

Javascript 将选项id从select元素传递到表单提交,javascript,php,html,Javascript,Php,Html,我使用selectform元素呈现多个选项,然后使用onchange事件在文本区域中显示来自数据库的相应文本 select选项的值很长,因此我想将该选项的id或name传递给我的表单target favorite.php,但我不知道如何做 HTML: <div class="container"> <div class="had"> <form name="det" action="vispage.php" method="POST"> <

我使用
select
form元素呈现多个选项,然后使用
onchange
事件在文本区域中显示来自数据库的相应文本

select
选项的值很长,因此我想将该选项的
id
name
传递给我的表单target 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

$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']
     );

}

?>

哈迪思的书名


树:


PHP:

<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

$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']
     );

}

?>


您是否必须使用href才能传递值,或者您是否愿意接受其他解决方案?@Terminus我也可以使用按钮更改表单提交到的位置如何?@Terminus how???@layla7是否将ID作为查询字符串传递?