|
|
|
เลื่อก auto complete แล้วให้ select box โชว์ข้อมูลภายใต้เงือนไขของ auto complete |
|
|
|
|
|
|
|
รอ........ผู้รู้ช่วยที
|
|
|
|
|
Date :
2013-01-07 17:12:59 |
By :
keng_ds |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หลักการคล้าย ๆ กับ Dependant List menu ครับ ขึ้นอยู่จะ Apply แบบไหน ลองค้นหาในกระทู้บทความเก่า ๆ ได้ครับ มีทั้ง JavaScript และ jQuery
|
|
|
|
|
Date :
2013-01-07 17:15:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Default.html
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<title>:: jQuery Auto Suggession ::</title>
<meta charset="UTF-8" />
<!-- CSS style -->
<link href="style.css" rel="stylesheet" type="text/css">
<!-- jQuery libs -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<form name="Myfrm" id="Myfrm" autocomplete=off>
<label>Name:</label>
<input type="text" name="txt_name" id="txt_name" onblur="setTimeout('txt_Out();', 200);" /><br />
<div id="result"></div>
<!--
<label>ID:</label>
<input type="text" name="txt_id" id="txt_id" />
-->
</form>
<!-- Javascript -->
<script type="text/javascript">
$(document).ready(function(){
$('#result').hide();
$('#txt_name').keyup(function(){
var txt_name = $('#txt_name').val();
if(txt_name != ""){
$.get('server.php', {qrstr:txt_name}, function(data){
/* Check return data from databases */
if(data != ""){
$('#result').show().html(data);
}else{
$('#txt_id').val('');
$('#result').hide().html('');
}
});
return false;
}else{
$('#txt_id').val('');
$('#result').hide().html('');
}
});
});
/* End */
/* Onblur txt_name */
function txt_Out(){
$('#result').hide().html('');
}
/* Onclick div#link */
function Add_ID(id, name){
$('#txt_name').val(name);
//$('#txt_id').val(id);
$('#result').hide().html('');
}
</script>
</body>
</html>
server.php
Code (PHP)
<?php
/* Fix request sometime don't dupicate */
header("Content-type:text/html; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
/* Connect to databases */
$link = mysql_connect("localhost", "root", "1234") or die (mysql_error());
$sel_db = mysql_select_db("student", $link);
/* Select data from table */
$sql = "SELECT * FROM tb_data WHERE Name LIKE '".$_GET["qrstr"]."%'";
$qr = mysql_query($sql);
$rows = mysql_num_rows($qr);
while($fetch = mysql_fetch_assoc($qr)){
echo "<div id=\"link\" onclick=\"Add_ID('".$fetch["id"]."', '".$fetch["name"]."');\"> ".$fetch["name"]."</div>";
}
/* Close connect databases */
mysql_close($link);
?>
style.css
Code
body{font-family:Arial; font-size:12px;text-align:center;}
label{display:inline-block;width:100px; text-align:right; font-weight:bold; color:#F00;}
div#result{
text-align:left;
margin-top:3px;
border:solid 1px #CCC;
width:450px;
background-color:#FFF;
position:absolute; left:510px;
}
div#link{width:100%;}
div#link:hover{background-color:#1E90FF;cursor:pointer; text-decoration:underline; color:#FFF;}
input{margin-top:3px;}
input#txt_name{width:350px;border:solid 1px #CCC;text-transform:uppercase;}
input#txt_name:focus{border:solid 1px #1E90FF;}
เอาไปประยุกต์ดูนะครับ
ปรึกษา php+MySQL ฟรีจร้า
koromankung[at]gmail.com
|
|
|
|
|
Date :
2013-01-07 17:21:40 |
By :
popnakub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ
|
|
|
|
|
Date :
2013-01-08 09:06:51 |
By :
keng_ds |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|