这是我的代码,它打印拥有ID_no的人的姓氏,该ID在下拉选项中。我想要的是在文本框中输出它,所以一旦选择了id_no,它将自动填充该字段:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "auth";
// Create connection
$conn = new mysqli("localhost", "root", "", "auth");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id_no,fn,sn,mn from employee ORDER BY id_no asc";
$result = $conn->query($sql);
?>
<select name='id_no' onchange="changeSelect(this.value)">
<?php while ($row = $result->fetch_array()) { ?>
<option value="<?php echo($row['sn']); ?>" >
<?php echo($row['id_no']); ?>
</option>
<?php } ?>
</select>
<div id="demo"></div>
<script>
function changeSelect(value)
{
document.getElementById("demo").innerHTML = value
}
</script>
<input type="text">
内容放在哪里?答案 0 :(得分:1)
<?php echo"<input type=text name=fullname size=50 value=$row[sn],$row[fn],$row[mn] required>";
是的,我做到了:)