|
 |
|
ปัญญาหาผมจะเอา AjaxAutoFill คู่กับ Ajax Check Username |
|
 |
|
|
 |
 |
|
พี่ครับผมสงสัยครับ
ผมจะเอา AjaxAutoFill คู่กับ Ajax Check Username
https://www.thaicreate.com/tutorial/ajax-auto-fill-textbox.html
https://www.thaicreate.com/tutorial/ajax-check-username.html
แต่มันเป็น OnChange ในการทำงานทั้งคู่
ไม่รู้ว่าสามารถแก้ไข ยังไงได้บ้างหรอครับพี่่
เป็นของ ajax-auto-fill-textbox
OnChange="JavaScript:doCallAjax2('txtUsername','book_name','book_number_number','book_coppy','textfield2');"
เป็นของ ajax-check-username
OnChange="JavaScript:doCallAjax();"
Code (PHP)
<input type="text" name="txtUsername" id="txtUsername" OnKeyPress="return chkNumber(this)" OnChange="JavaScript:doCallAjax('txtUsername','book_name','book_number_number','book_coppy','textfield2');" OnChange="JavaScript:doCallAjax();">
Tag : PHP, MySQL, JavaScript, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2012-02-24 00:46:01 |
By :
numprick |
View :
1065 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
OnChange="JavaScript:doCallAjax('txtUsername','book_name','book_number_number','book_coppy','textfield2');doCallAjax();"
ใส่ต่อกันได้เลยครับ 
|
 |
 |
 |
 |
Date :
2012-02-24 06:26:49 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่อันที่จริงไปเขียน function ไว้ที่เดียวไว้ใน php จะดีกว่าครับ
|
 |
 |
 |
 |
Date :
2012-02-24 06:27:17 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองแล้วครับพี่ชายแต่มันก็ยังไม่ทำงาน
Code (PHP)
<script language="JavaScript">
//check input only number
function chkNumber(ele)
{
var vchar = String.fromCharCode(event.keyCode);
if ((vchar<'0' || vchar>'9') && (vchar != '.')) return false;
ele.onKeyPress=vchar;
}
//check same ISBN
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxPHPRegister2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "..";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'AjaxPHPRegister3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
//autofill
var HttPRequest = false;
function doCallAjax2(fProductID,fProductName,fPrice,ffield) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxPHPRegister2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "..";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'AjaxPHPRegister3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<input type="text" name="txtUsername" id="txtUsername" OnKeyPress="return chkNumber(this)" OnChange="JavaScript:doCallAjax2('txtUsername','book_name','book_number_number','book_coppy','textfield2');doCallAjax();">
ในอันนี้มี 3 สคริป
1 บังคับใส่ตัวเลข
2 เช็คค่าว่าง
3 ดึงข้อมูลมาแสดง
อันนี้ผมทำงานได้แต่เช็คค่าว่างครับ ไม่สามารถดึง AutoFill ได้ครับ
เขียน function ไว้ที่เดียวไว้ใน php อันนี้ทำอย่างไรครับ
น้องขอสอบถามครับ
|
 |
 |
 |
 |
Date :
2012-02-24 09:01:09 |
By :
numprick |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|