從組合框中選擇值時,名稱和年齡文本框應通過從數據庫獲取數據來顯示值。根據組合框更改兩個文本框的值
這名工作正常,但我不知道怎麼去顯示年齡也
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="jquerylib.js"></script>
</head>
<body>
<form>
<table border="0">
<tr>
<td>
Select :
//here the combobox selection
<select name="name" id="C_NAME" >
<option value="">Select a person:</option>
<option value="1">SULOCHANA</option>
<option value="2">COLOMBO</option>
<option value="3">PILIYANDALA76</option>
<option value="4">RAJAGIRIYA</option>
</select>
</td>
</tr>
<tr>
<td>
Display
//display name
<input name="dis_name" type="text" id="display_name" size="30" />
//display age
<input name ="age" type="text" id="age" />
</td>
</tr>
C_NAME
是組合框ID
<script>
$("select").change(function() {
var str =$("#C_NAME").val();
if(str!=""){
$.get("get_name.php", {id: str}, function(data){
//get the value from the get_name.php file and asign to display_name text filed
$("#display_name").val(data);});
}`
})
.change();
</script>
here is get_name.php
<?php
include('db.php');
//getting the passed value using get
$ID = intval($_GET['id']);
$sql= mysql_query("SELECT * FROM system_user_tb WHERE id = '".$ID."'");
$row = mysql_fetch_array($sql);
echo $row['ID']." - " .$row['Login_name'];
?>
調試,看看您是否正確發送的查詢字符串ID。也在那裏調試你的迴應,這可能有幫助。 – 2014-10-30 12:37:05
沒有結果是與單個文本框的okey 我不知道關於ajax ,爲什麼要問如何得到第二個值 – 2014-10-30 12:40:32
你確定字符'不是一個錯字嗎?在行$(「#display_name」)。val(data);}); }'' – 2014-10-30 12:45:42