|
 |
|
เพิ่มfunctionนี้ แต่อีก functionเดิม ใช้ไม่ได้ซะนั้น เพราะกะไรหรือคับ |
|
 |
|
|
 |
 |
|
ก่อนอื่นต้องขอขอบพระคุณ http://cakephp.jitwitya.com/post/jquery-auto-province & http://cakephp.jitwitya.com/post/check-username-by-jquery-ajax อย่างสูงมากๆ ที่ผมได้นำมาใช้
เดิมที function auto province ใช้งานได้ ใส่ function check database ไปแล้ว auto province ก็ใช้ไม่ได้ เป็นเพราะอะไร ผิดตรงไหน และที่จริงแล้วต้องยังไง ขอบคุณครับ
:: function check database ::
Code (PHP)
<?php
include("config.php");
mysql_query("SET NAMES 'tis620'");
//create test data
$r = mysql_query("SHOW TABLES LIKE 'applymember'");
if (mysql_num_rows($r) == 0){
echo 'create table successfully.<br>';
mysql_query(
"insert into `SMALLINL`(`id`,`IDMember`) values ".
"(1,'abc'),".
"(2,'abc2'),".
"(3,'abc3'),".
"(4,'abc4');"
) or die(mysql_error());
echo 'insert data successfully.<br>';
}
//ajax process
if (isset($_GET['userExists'])){
$IDMember = mysql_real_escape_string($_POST['IDMember']);
$r = mysql_query("SELECT 1 FROM applymember WHERE IDMember='$IDMember'");
echo mysql_num_rows($r)?'yes':'no';
exit(0);
}
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('#check-user-exists-button').click(function(e){
var user = $.trim($('#applymember input[name=IDMember]').val());
if (user.length == 0){
alert('please enter the IDMember');
} else {
$.ajax({
url: '?userExists',
type: 'POST',
dataType: 'html',
data: $('#applymember').serialize(),
success: function(data){
if (data.indexOf('yes') != -1){
alert("ID '" + user + "'ไม่สามารถใช้ได้,\กรุณาใส่IDใหม่");
} else {
alert("รหัสนี้ใช้ได้ '" + user + "' ");
}
}
});
}
e.preventDefault();
});
});
</script>
[.php][/code]
CODE.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>applymember</title>
<link rel="stylesheet" type="text/css" href="auto-province/jquery.auto-province.css" />
<script type="text/javascript" src="auto-province/jquery.js"></script>
<script type="text/javascript" src="auto-province/jquery.auto-province.js"></script>
<script type="text/javascript">
$(function(){
$('#District').AutoProvince({
amphur:'#Amper',
province:'#Province',
postcode:'#Postcode'
});
$('#ap-tumbol').AutoProvince();
});
</script>
<SCRIPT LANGUAGE="JavaScript"> //check text box
function checkmemlogin(){
if(document.forms.applymember.IDMember.value == "")
{
alert("กรุณาใส่รหัสมาชิก"); //alert with appropriate message
document.forms.applymember.IDMember.select(); //place cursor on the input box
return false;
}
if(document.forms.applymember.pwmember.value == "")
{
alert("กรุณาใส่รหัสผ่าน");
document.forms.applymember.pwmember.select();
return false;
}
if(document.forms.applymember.Names.value == "")
{
alert("กรุณาใส่ชื่อสมาชิก");
document.forms.applymember.Names.select();
return false;
}
if(document.forms.applymember.date.value == "")
{
alert("กรุณาใส่วันที่สมัคร");
document.forms.applymember.date.select();
return false;
}
}
</SCRIPT>
<?php
include("config.php");
mysql_query("SET NAMES 'tis620'");
//create test data
$r = mysql_query("SHOW TABLES LIKE 'applymember'");
if (mysql_num_rows($r) == 0){
echo 'create table successfully.<br>';
mysql_query(
"insert into `SMALLINL`(`id`,`IDMember`) values ".
"(1,'abc'),".
"(2,'abc2'),".
"(3,'abc3'),".
"(4,'abc4');"
) or die(mysql_error());
echo 'insert data successfully.<br>';
}
//ajax process
if (isset($_GET['userExists'])){
$IDMember = mysql_real_escape_string($_POST['IDMember']);
$r = mysql_query("SELECT 1 FROM applymember WHERE IDMember='$IDMember'");
echo mysql_num_rows($r)?'yes':'no';
exit(0);
}
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('#check-user-exists-button').click(function(e){
var user = $.trim($('#applymember input[name=IDMember]').val());
if (user.length == 0){
alert('please enter the IDMember');
} else {
$.ajax({
url: '?userExists',
type: 'POST',
dataType: 'html',
data: $('#applymember').serialize(),
success: function(data){
if (data.indexOf('yes') != -1){
alert("ID '" + user + "'ไม่สามารถใช้ได้,\กรุณาใส่IDใหม่");
} else {
alert("รหัสนี้ใช้ได้ '" + user + "' ");
}
}
});
}
e.preventDefault();
});
});
</script>
</head>
<body>
<form id="applymember" name="applymember" method="post" action="" onSubmit="return checkmemlogin();">
<p>รหัสสมาชิก: <span class="style10">
<input name="IDMember" type="text" id="IDMember2" size="10" maxlength="9" />
</span> <span class="style10">
<input name="button" type="button" id="check-user-exists-button" value="check IDMember" />
<br />
</span>รหัสผ่าน:
<input name="pwmember" type="text" id="pwmember" size="6" maxlength="6" />
<br />
ชื่อ-นามสกุล:
<input name="Names" type="text" id="Names" size="30" maxlength="50" />
<br />
วันที่สมัคร:
<input id="date" name="date" type="text" style="width: 80px;" maxlength="10" />
<br />
ว/ด/ป เกิด:
<input name="BirthDay" type="text" id="BirthDay" size="10" maxlength="50" />
<br />
รหัสบัตรประชาชน::
<input name="People" type="text" id="People" size="15" maxlength="13" />
<br />
บ้านเลขที่:
<input name="Address" type="text" id="address" size="30" maxlength="50" autocomplete="off" />
<br />
เขต/ตำบล:
<input autocomplete="on" name="District" id="District" type="text" size="30" />
<br />
แขวง/อำเภอ:
<input autocomplete="on" name="Amper" id="Amper" type="text" size="30" />
<br />
จังหวัด:
<input autocomplete="on" name="Province" id="Province" type="text" size="30" />
<br />
รหัสไปรษณีย:
<input autocomplete="on" name="PostCode" id="Postcode" type="text" size="10" />
<input type="submit" name="submit" id="submit" value=" บันทึก " class="content03" />
</p>
</form>
</body>
</html>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-10-31 13:17:12 |
By :
gofgof |
View :
1431 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สองไฟล์นี้เป็นไฟล์เดียวกันครับ
<script type="text/javascript" src="auto-province/jquery.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
ให้ลบเอาอันนี้ออกไปครับ
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
|
 |
 |
 |
 |
Date :
2009-10-31 13:54:25 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษคับไม CODE.PHP ขอผมเป็นแบบนี้อ่ะตอนPreview ไม่ได้เป็นแบบนี้นิคับ งง
|
 |
 |
 |
 |
Date :
2009-10-31 13:56:29 |
By :
gofgof |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สงสัยเป็นเพราะ [.php] ครับต้องเขียน [/php] น่ะครับ
|
 |
 |
 |
 |
Date :
2009-10-31 14:06:05 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องขอโทษที่โพส No.2 เพราะ Google Chrome ของผม error คับ
ขอบคุณ คุณ num คับ ใช้ได้แล้วคับ
(ไม่ดูให้ดีอีกแล้วเรา โทษที คับ)
|
 |
 |
 |
 |
Date :
2009-10-31 14:08:42 |
By :
gofgof |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2009-10-31 14:21:15 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|