|
 |
|
อยากตรวจสอบค่าจากฐานข้อมูลว่าตรงกับค่าที่กรอกใน text field หรือไม่(เช็ค แล้ว alert ในหน้าเดียวกัน) |
|
 |
|
|
 |
 |
|
จะตรวจสอบค่าที่เป็นสตริงได้อย่างไรคะ
ในทีนี้เอาค่ารหัสสมาชิกมาจากฐานข้อมูล เป็นชนิด varchar ค่ะ
เช่น m0001
คำสั่ง alert อื่นๆ ปกติค่ะ แต่คำสั่งสุดท้ายในฟังชั่น check มันไม่ทำงานค่ะ ลองมั่วมาหลายชั่วโมงแล้วค่ะ คืออยาจะตรวจสอบว่า ค่ารหัสสมาชิกที่ใส่มามันตรงกับที่มีในฐานข้อมูลหรือไม่ ถ้าตรงกันให้ alert และคืนค่าเป็น false ค่ะ รบกวนช่วยดูด้วยนะคะ
<form name ="checkForm" action="addraisepay2.php" method="post" onSubmit="return check()">
<table border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td colspan="2"> <p align="center"> <center>
<font color="#333333" size="2">ระบบเพิ่มข้อมูลเงินปัญผลและเฉลี่ยคืน</font>
<strong><font color="#333333" size="2" face="MS Sans Serif, Tahoma, sans-serif">
</font></strong>
</center></p></td>
</tr>
<tr>
<td><p><font size="2" face="MS Sans Serif, Tahoma, sans-serif"> เปอร์เซ็นต์ของเงินปันผล:</font></p></td>
<td><input name="pp" type="text" id="pp" size="5" maxlength="10">
% <img src="images/Star16.png" width="16" height="16" align="middle" /></td>
</tr>
<tr>
<td><p><font size="2" face="MS Sans Serif, Tahoma, sans-serif"> เปอร์เซ็นต์ของเงินเฉลี่ยคืน</font><font size="2" face="MS Sans Serif, Tahoma, sans-serif">:</font></p></td>
<td><input name="pav" type="text" id="pav" size="5" maxlength="10">
% <img src="images/Star16.png" width="16" height="16" align="middle" /></td>
</tr>
<tr>
<td><font size="2" face="MS Sans Serif, Tahoma, sans-serif"> จำนวนเงินปันผลที่ได้:</font></td>
<td><input name="moneyp" type="text" id="moneyp" size="10" maxlength="10"> <font size="-1">บาท</font><img src="images/Star16.png" width="16" height="16" align="middle" /></td>
</tr>
<tr>
<td><font size="2" face="MS Sans Serif, Tahoma, sans-serif"> จำนวนเงินเฉลี่ยคืนที่ได้:</font></td>
<td><input name="moneyav" type="text" id="moneyav" size="10" maxlength="10"> <font size="-1">บาท</font><img src="images/Star16.png" width="16" height="16" align="middle" /></td>
</tr>
<tr>
<td><p><font size="2" face="MS Sans Serif, Tahoma, sans-serif"> รหัสสมาชิก :</font></p></td>
<td><input name="memid" type="text" id="memid" size="20" maxlength="5">
<img src="images/Star16.png" width="16" height="16" align="middle" /></td>
</tr>
<tr>
<td colspan="2">
<center>
<label>ตกลง
<input name="Submit" type="image" id="Submit" value="Submit" src="images/yes.png" width="24" height="24" align="middle" />
</label>
<?
$memid = $_GET["memid"];
$sqlx = "select * from co_raisepay where member_id = '$memid'" ;
$resultx = mysql_query($sqlx) ;
$numx = mysql_num_rows($resultx);
$recordx=mysql_fetch_array($resultx);
$mid=$recordx[member_id];
?>
<input name="mid" type="hidden" id="mid" value="<?=$mid?>">
<input name="ok" type="hidden" id="ok" value="ok_pass"></center>
</tr>
</table>
<script language="javascript">
function check() {
if(isNaN(document.checkForm.pp.value)) {
alert("กรุณากรอกเปอร์เซ็นต์ของเงินปันผลเฉพาะตัวเลขนะครับ") ;
document.checkForm.pp.focus() ;
return false ;
}
else if(document.checkForm.pp.value=="") {
alert("กรุณากรอกเปอร์เซ็นต์ของเงินปันผลด้วยนะครับ") ;
document.checkForm.pp.focus() ;
return false ;
}
else if(isNaN(document.checkForm.pav.value)) {
alert("กรุณากรอกเปอร์เซ็นต์ของเงินเฉลี่ยคืนเฉพาะตัวเลขนะครับ") ;
document.checkForm.pav.focus() ;
return false ;
}
else if(document.checkForm.pav.value=="") {
alert("กรุณากรอกเปอร์เซ็นต์ของเงินเฉลี่ยคืนด้วยนะครับ") ;
document.checkForm.pav.focus() ;
return false ;
}
if(isNaN(document.checkForm.moneyp.value)) {
alert("กรุณากรอกเงินปันผลเฉพาะตัวเลขนะครับ") ;
document.checkForm.moneyp.focus() ;
return false ;
}
else if(document.checkForm.moneyp.value=="") {
alert("กรุณากรอกเงินปันผลด้วยนะครับ") ;
document.checkForm.moneyp.focus() ;
return false ;
}
else if(isNaN(document.checkForm.moneyav.value)) {
alert("กรุณากรอกเงินเฉลี่ยคืนเฉพาะตัวเลขนะครับ") ;
document.checkForm.moneyav.focus() ;
return false ;
}
else if(document.checkForm.moneyav.value=="") {
alert("กรุณากรอกเงินเฉลี่ยคืนด้วยนะครับ") ;
document.checkForm.moneyav.focus() ;
return false ;
}
else if(document.checkForm.memid.value=="") {
alert("กรุณากรอกรหัสสมาชิกด้วยนะครับ") ;
document.checkForm.memid.focus();
return false ;
}
else if(document.checkForm.memid.value==document.checkForm.mid.value)
{
alert('รหัสสมาชิกนี้มีข้อมูลเงินปันผลอยู่ในระบบแล้วค่ะ');
document.checkForm.memid.focus();
return false ;
}
else {
return true ;
}
}
</script>
<p> </p>
<p>
</p>
</form>
Tag : PHP, JavaScript

|
|
 |
 |
 |
 |
Date :
2011-04-21 16:25:28 |
By :
Zonza |
View :
1287 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 03
|