|
|
|
ดึงข้อมูลจากฐานข้อมูลมาแสดงใน ListBox พอเลือกแสดงไปยัง TextBox หลายค่า |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<title>:: Check listbox ::</title>
<meta charset="UTF-8" />
</head>
<body>
Listbox :
<select name='ddl' id='ddl'>
<option value='0'>--SELECT--</option>
<option value='1'>COM1</option>
<option value='2'>COM2</option>
<option value='3'>COM3</option>
</select>
Box : <input type='text' name='txt_box' id='txt_box' />
</body>
</html>
<script type='text/javascript'>
$(document).ready(function(){
$('#ddl').change(function(){
var ddl = $('#ddl').val();
if(ddl == 0){
$('#txt_box').val('');
}else{
$.getJSON('get_data.php?tMode=getdata&ddl='+ddl, function(data){
$('#txt_box').val(data[0].data);
});
//return false;
}
});
});
</script>
|
|
|
|
|
Date :
2012-12-15 09:54:48 |
By :
popnakub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
$ddl = $_GET['ddl'];
if($_GET['tMode'] == 'getdata'){
$link = mysql_connect("localhost", "root", "") or die (mysql_error());
$sel_db = mysql_select_db("student", $link);
mysql_query("SET NAMES UTF8");
$sql = "SELECT data FROM table WHERE id = '".$ddl."' ";
$qr = mysql_query($sql);
while($fetch = mysql_fetch_assoc($qr)){
$json_arr = array(
"data"=>$fetch["data"],
);
$json = json_encode($json_arr);
}
echo $json;
}
?>
|
|
|
|
|
Date :
2012-12-15 09:55:10 |
By :
popnakub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันยังไงก็ลองเอาไปรัน ไปใช้งานดูครับ เด๋วก็รู้ อิอิ
|
|
|
|
|
Date :
2013-05-15 11:04:59 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|