|
|
|
คลิกที่ปุ่มจะมี popup ขึ้นมาให้เลือกข้อมูลซึ่งดึงมาจากฐานข้อมูล เลือกข้อมูลที่ต้องการจะส่งค่ากลับมาที่ form หลัก |
|
|
|
|
|
|
|
Code หบบบละ หรือจะให้เดาตอบ
|
|
|
|
|
Date :
2012-09-29 15:28:13 |
By :
aa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Overtime Requisition Form</title>
<script language="JavaScript" src="date-picker.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[name*="txtCustomerID"]').change("change", function (){
var currentIndex = $(this).closest("tr")[0].rowIndex;
$.ajax({
url: "returnEmployee.php" ,
type: "POST",
data: 'sCusID=' +$("#txtCustomerID"+currentIndex).val()
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj == '')
{
$("#txtCustomerID"+currentIndex).val('');
$("#txtName"+currentIndex).val('');
$("#txtEmail"+currentIndex).val('');
$("#txtCountryCode"+currentIndex).val('');
$("#txtBudget"+currentIndex).val('');
$("#txtUsed"+currentIndex).val('');
$("#txtUserid"+currenIndex).val('');
$("#txtdepart"+currenIndex).val('');
}
else
{
$.each(obj, function(key, inval) {
$("#txtCustomerID"+currentIndex).val(inval["Emp_id"]);
$("#txtName"+currentIndex).val(inval["Emp_name"]);
$("#txtEmail"+currentIndex).val(inval["Emp_surname"]);
$("#txtCountryCode"+currentIndex).val(inval["Position"]);
$("#txtBudget"+currentIndex).val(inval["Address"]);
$("#txtUsed"+currentIndex).val(inval["Phone"]);
$("#txtUserid"+currenIndex).val(inval["User_User_id"]);
$("#txtdepart"+currenIndex).val(inval["Department_Department_id"]);
});
}
});
});
});
function OpenPopup(intLine)
{
window.open('getPoint.php','myPopup','width=650,height=200,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
</script>
</head>
<body>
<table width="833" border="1" align="center" id="tbExp">
<tr class="name">
<th width="84"> <div align="center">Emp.ID </div></th>
<th width="120"> <div align="center">Employeename </div></th>
<th width="90"> <div align="center">Surname</div></th>
<th width="89"> <div align="center">Total Hours </div></th>
<th width="156"> <div align="center">Bus Route </div></th>
<th width="95"> <div align="center">Each Emp. </div></th>
<th width="78"> <div align="center">Reason </div></th>
<th width="69"> <div align="center">Used </div></th>
</tr>
<?
for($i=1;$i<=15;$i++)
{
?>
<tr class="text">
<td><input type="text" name="txtCustomerID<?=$i;?>" id="txtCustomerID<?=$i;?>" size="5"></td>
<td><input name="txtName<?=$i;?>" type="text" disabled="disabled" id="txtName<?=$i;?>"size="20" /></td>
<td><input name="txtEmail<?=$i;?>" type="text" disabled id="txtEmail<?=$i;?>" size="15"></td>
<td></td>
<td align="lesf"><input type="text" name="txtCustomerID_" id="txtCustomerID_" /></td>
<td align="left"><input name="txtName_" id="txtName_" size="15" /></td>
<td align="left"></td>
<td align="left"><input type="submit" name="popup" id="popup" value="......" onclick="OpenPopup( );"></td>
</tr>
<?
}
?>
</table>
</body>
</html>
returnEmployee.php
Code (PHP)
<?
include("config.inc.php");
{
$strSQL = "SELECT * FROM employee WHERE 1 AND Emp_id = '".$_POST["sCusID"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
echo json_encode($resultArray);
}
?
getPoint.php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
</head>
<script language="javascript">
function selData(intLine,CustomerID,Name)
{
var sCustomerID = self.opener.document.getElementById("txtCustomerID_" );
sCustomerID.value = CustomerID;
var sName = self.opener.document.getElementById("txtName_" );
sName.value = Name;
/*var sEmail = self.opener.document.getElementById("txtEmail_" +intLine);
sEmail.value = Email;
var sCountryCode = self.opener.document.getElementById("txtCountryCode_" +intLine);
sCountryCode.value = CountryCode;
var sBudget = self.opener.document.getElementById("txtBudget_" +intLine);
sBudget.value = Budget;
var sUsed = self.opener.document.getElementById("txtUsed_" +intLine);
sUsed.value = Used;*/
window.close();
}
</script>
<body>
<?
include("config.inc.php");
$strSQL = "SELECT * FROM busappoint_rayong order by BusAp_name asc";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="90"> <div align="center">ลำดับที่ </div></th>
<th width="168"> <div align="center">จุดขึ้นรถ </div></th>
<th width="83"> <div align="center">เวลาเช้า </div></th>
<th width="96"> <div align="center">เวลาดึก </div></th>
<th width="57"> <div align="center">สายรถ </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><a href ="javascript:void:(0);" OnClick="selData('<?=$objResult["BusAp_id"];?>','<?=$objResult["BusAp_name"];?>');">
<?=$objResult["BusAp_id"];?></a></div></td>
<td><?=$objResult["BusAp_name"];?></td>
<td><?=$objResult["BusAp_day"];?></td>
<td><div align="center"><?=$objResult["BusAp_night"];?></div></td>
<td align="right"><?=$objResult["BusRoute_Bus_id"];?></td>
</tr>
<?
}
?>
</table>
</body>
</html
โค้ดที่ใช้ ดูตัวอย่างจากในเว็บแล้วมาแก้ไข ลองมั่วๆ ไม่ค่อยเข้าใจ ช่วยหน่อยนะคะ
|
|
|
|
|
Date :
2012-09-29 15:51:46 |
By :
moha |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กลับไปตัวอย่างครับ
|
|
|
|
|
Date :
2012-09-30 08:16:54 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|