|
|
|
สอบถามเรื่อง กรอกid ช่องแรก แล้วดึงข้อมูลมาโชว์ ช่องสอง ครับ อ้างอิงจาก jQuery Auto Fill |
|
|
|
|
|
|
|
อ้างอิงจาก https://www.thaicreate.com/community/jquery-auto-fill-textbox.html
ลองเอาไปรันแล้ว แต่รันไม่มีอะไรเกิดขึ้นคับ เพราะอะไร
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer WHERE 1 AND CustomerID = '".$_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);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
Sample3.php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
<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: "returnCustomer3.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('');
}
else
{
$.each(obj, function(key, inval) {
$("#txtCustomerID"+currentIndex).val(inval["CustomerID"]);
$("#txtName"+currentIndex).val(inval["Name"]);
$("#txtEmail"+currentIndex).val(inval["Email"]);
$("#txtCountryCode"+currentIndex).val(inval["CountryCode"]);
$("#txtBudget"+currentIndex).val(inval["Budget"]);
$("#txtUsed"+currentIndex).val(inval["Used"]);
});
}
});
});
});
</script>
</head>
<body>
<h2>jQuery Auto fill ดึงข้อมูลอัตโนมัติ แบบตารางหลายแถว</h2>
<form action="phpMySQLAddSave.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<?
for($i=1;$i<=10;$i++)
{
?>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID<?=$i;?>" id="txtCustomerID<?=$i;?>" size="5"></div></td>
<td><input type="text" name="txtName<?=$i;?>" id="txtName<?=$i;?>" size="20"></td>
<td><input type="text" name="txtEmail<?=$i;?>" id="txtEmail<?=$i;?>" size="25"></td>
<td><div align="center"><input type="text" name="txtCountryCode<?=$i;?>" id="txtCountryCode<?=$i;?>" size="2"></div></td>
<td align="right"><input type="text" name="txtBudget<?=$i;?>" id="txtBudget<?=$i;?>" size="5"></td>
<td align="right"><input type="text" name="txtUsed<?=$i;?>" id="txtUsed<?=$i;?>" size="5"></td>
</tr>
<?
}
?>
</table>
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
</body>
</html>
Tag : PHP, JavaScript, Ajax, jQuery
|
ประวัติการแก้ไข 2014-09-06 13:40:38 2014-09-06 14:26:49
|
|
|
|
|
Date :
2014-09-06 13:39:08 |
By :
031130 |
View :
1146 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[name*="txtCustomerID"]').change("change", function (){
var rel = $(this).attr('rel');
$.ajax({
url: "returnCustomer3.php" ,
type: "POST",
data: 'sCusID=' +$(this).val();
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj == '')
{
$("#txtCustomerID"+rel).val('');
$("#txtName"+rel).val('');
$("#txtEmail"+rel).val('');
$("#txtCountryCode"+rel).val('');
$("#txtBudget"+rel).val('');
$("#txtUsed"+rel).val('');
}
else
{
$.each(obj, function(key, inval) {
$("#txtCustomerID"+rel).val(inval["CustomerID"]);
$("#txtName"+rel).val(inval["Name"]);
$("#txtEmail"+rel).val(inval["Email"]);
$("#txtCountryCode"+rel).val(inval["CountryCode"]);
$("#txtBudget"+rel).val(inval["Budget"]);
$("#txtUsed"+rel).val(inval["Used"]);
});
}
});
});
});
</script>
</head>
<body>
<h2>jQuery Auto fill ดึงข้อมูลอัตโนมัติ แบบตารางหลายแถว</h2>
<form action="phpMySQLAddSave.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<?
for($i=1;$i<=10;$i++)
{
?>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID[]" id="txtCustomerID" rel="<?=$i;?>" size="5"></div></td>
<td><input type="text" name="txtName[]" id="txtName<?=$i;?>" size="20"></td>
<td><input type="text" name="txtEmail[]" id="txtEmail<?=$i;?>" size="25"></td>
<td><div align="center"><input type="text" name="txtCountryCode[]" id="txtCountryCode<?=$i;?>" size="2"></div></td>
<td align="right"><input type="text" name="txtBudget[]" id="txtBudget<?=$i;?>" size="5"></td>
<td align="right"><input type="text" name="txtUsed[]" id="txtUsed<?=$i;?>" size="5"></td>
</tr>
<?
}
?>
</table>
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
</body>
</html>
|
|
|
|
|
Date :
2014-09-06 16:42:22 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองแก้แล้ว ผลก็ยังนิ่งอยู่ ครับ
Code (PHP)
<?php
session_start();
include "session.php";
include("config.inc.php");
include('fnalert.php');
include('datetimepicking.php');
session_id();
?>
<?
$strSQL = "SELECT * FROM `stock` WHERE 1 AND stock_num_run = '".$_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);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
<html>
<head>
<title>ThaiCreate.Com</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[name*="stock_num_run"]').change("change", function (){
var rel = $(this).attr('rel');
$.ajax({
url: "returnCustomer3.php" ,
type: "POST",
data: 'sCusID=' +$(this).val()
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj == '')
{
$("#stock_num_run"+rel).val('');
$("#sum_vat"+rel).val('');
$("#Condition_due_date"+rel).val('');
}
else
{
$.each(obj, function(key, inval) {
$("#stock_num_run"+rel).val(inval["stock_num_run"]);
$("#sum_vat"+rel).val(inval["sum_vat"]);
$("#Condition_due_date"+rel).val(inval["Condition_due_date"]);
});
}
});
});
});
</script>
</head>
<body>
<h2>jQuery Auto fill ดึงข้อมูลอัตโนมัติ แบบตารางหลายแถว</h2>
<form action="phpMySQLAddSave.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
</tr>
<?
for($i=1;$i<=10;$i++)
{
?>
<tr>
<td><div align="center"><input type="text" name="stock_num_run[]" id="stock_num_run" rel="<?=$i;?>" size="5"></div></td>
<td><input type="text" name="sum_vat[]" id="sum_vat<?=$i;?>" size="20"></td>
<td><input type="text" name="Condition_due_date[]" id="Condition_due_date<?=$i;?>" size="25"></td>
</tr>
<?
}
?>
</table>
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
</body>
</html>
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[name*="stock_num_run"]').change("change", function (){
var rel = $(this).attr('rel');
$.ajax({
url: "returnCustomer3.php" ,
type: "POST",
data: 'sCusID=' +$(this).val()
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj == '')
{
$("#stock_num_run"+rel).val('');
$("#sum_vat"+rel).val('');
$("#Condition_due_date"+rel).val('');
}
else
{
$.each(obj, function(key, inval) {
$("#stock_num_run"+rel).val(inval["stock_num_run"]);
$("#sum_vat"+rel).val(inval["sum_vat"]);
$("#Condition_due_date"+rel).val(inval["Condition_due_date"]);
});
}
});
});
});
</script>
</head>
<body>
<h2>jQuery Auto fill ดึงข้อมูลอัตโนมัติ แบบตารางหลายแถว</h2>
<form action="phpMySQLAddSave.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
</tr>
<?
for($i=1;$i<=10;$i++)
{
?>
<tr>
<td><div align="center"><input type="text" name="stock_num_run[]" id="stock_num_run" rel="<?=$i;?>" size="5"></div></td>
<td><input type="text" name="sum_vat[]" id="sum_vat<?=$i;?>" size="20"></td>
<td><input type="text" name="Condition_due_date[]" id="Condition_due_date<?=$i;?>" size="25"></td>
</tr>
<?
}
?>
</table>
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
</body>
</html>
|
|
|
|
|
Date :
2014-09-08 11:55:27 |
By :
031130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Server เป็น apche หรือ iis ครับ
PHP version อะไรครับ
|
|
|
|
|
Date :
2014-09-08 12:01:07 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปิดด้วย firefox แล้วติดตั้งปลั๊กอินชื่อ firefox ลองใช้ firebug ส่งดูเออเร่อตรง console หรือค่าที่คืนกลับมาว่าถูกต้องรึเปล่า??
|
|
|
|
|
Date :
2014-09-08 12:36:40 |
By :
{Cyberman} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|