我想问一下JavaScript onchange
函数和PHP。
我有从db(MySql)获得的值的组合框,这是我的进步:
这是我的数据库内容:
member:
person_name (person one, person two, person three)
description ("sdsdsdsds","ewewewewe","gfdfdfdff","dfdfdfdfdfS")
PHP:
include "conn.php";
$query = "SELECT person_name FROM member";
$result = mysql_query($query);
echo "<select name='name'>";
echo "<option value=''>-Select-</option>";
while($row = mysql_fetch_array($result)) {
echo "<option value='".$row['person_name']."'>".$row['person_name']."</option>";
}
echo "</select>";
所以,当我选择其中一个值时,我想要空白的textarea,
<textarea>"FILLED WITH DESCRIPTION FROM DB BASED ON NAME SELECTED</textarea>
答案 0 :(得分:0)
我认为你正在寻找这个 -
echo "<select name='name' id='sel_id' onchange='fillData()'>";
echo "<option value=''>-Select-</option>";
while($row = mysql_fetch_array($result)) {
echo "<option value='".$row['person_name']."'>".$row['person_name']."</option>";
}
echo "</select>";
echo "<textarea id='txt_id'></textarea>";
function fillData(){
var s = document.getElementById("sel_id");
var val = s.options[s.selectedIndex].text;
document.getElementById("txt_id").innerHTML = val;
}
请注意:我还没有测试过。