2015-01-07 75 views
-1

這是我的代碼,用於打印擁有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">啄:所以一旦id_no上被選中它會自動填充該字段我想是在文本框中它的輸出?
+1

好了,問題是什麼?錯誤,如果有的話?檢查他們? –

+0

沒有錯誤 –

+0

所以你可以更新你的問題與完整的HTML生成? 或提供一個鏈接到您的網頁? – Alex

回答

1
<?php echo"<input type=text name=fullname size=50 value=$row[sn],$row[fn],$row[mn] required>"; 

是的,我做到了:)

相關問題