0
選擇選擇框時,我想從數據庫中創建一個<input type="text"></input>
放置文本。這裏是我的jQuery代碼jQuery:選擇框不響應
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function() {
$('#noID').change(function() {
var noID = $(this).val();
$.ajax({
type: 'POST',
url: 'ambilusername.php',
data: 'noID=' + noID,
success: function(response) {
$('#username').val(response);
}
});
});
});
</script>
,這裏是我的 「ambilusername.php」
<?php
include "../include/koneksi_db.php";
$noID = $_POST["noID"];
$username = mysql_query("SELECT * FROM booking_tamu WHERE noID='$noID'");
while($k = mysql_fetch_array($username)){
echo "$k[email]";
}
?>
這裏是我的全部的index.php代碼:
<?php
include "../include/koneksi_db.php";
?>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function() {
$('#noID').change(function() {
var noID = $(this).val();
$.ajax({
type: 'POST',
url: 'ambilusername.php',
data: 'noID=' + noID,
success: function(response) {
$('#username').val(response);
}
});
});
});
</script>
</head>
<body>
<form method="post" action="?page=prosesTambahAkun">
<table class="table-data" width=100% border=1>
<tr><td colspan="2" class="head-data">Tambah Data Akun</td></tr>
<tr>
<td class="pinggir-data">ID Pemesan</td>
<td>
<select name="noID" id="noID" required>
<option value="">------Pilih ID Pemesan------</option>
<?php
$query = "SELECT no_booking, COUNT(no_booking) AS 'jumlah' FROM booking_tamu GROUP BY no_booking ASC";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil)){
echo "<option value='".$data['no_booking']."'>".$data['no_booking']."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td class="pinggir-data">Username</td>
<td>
<input type="text" id="username" name="username" size="30px" readonly></input>
</td>
</tr>
<tr><td colspan="2" align="center" class="head-data">
<input type="submit" value="Tambah" name="tambah">
</td></tr>
</table>
</form>
</body>
</html>
的問題是,當我選擇在選擇框上的值,文本框不會把東西放在它上面。你能幫我麼?