|
|
|
javascript ดักจับ key ที่พิมพ์ ตัวที่ 1 ให้กรอกเฉพาะ 1,2,Sตัวที่ 2 ให้กรอกเฉพาะ /ตัวที่ 3 ให้กรอก |
|
|
|
|
|
|
|
ลองนำไป apply ดูครับ ไม่แน่ใจ
Code (PHP)
<script language="javascript">
function checkID(id)
{
if(document.form1.zipcode.value == ""){
alert('ข้อความที่ต้องการ');
document.form1.zipcode.focus();
return false;
}
else if(isNaN(document.form1.ชื่อtextbox.value)) {
alert("ข้อความเช่น ต้องกรอกเป็นตัวเลขเท่านั้น") ;
document.form1.zipcode.focus() ;
return false ;
}
document.form1.submit();
}
</script>
ประมาณนี่รึป่าวครับลองดู
|
|
|
|
|
Date :
2010-04-02 06:55:04 |
By :
chonburi f.c |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูอันนี้ก็ได้ครับ แล้วเอาไปประยุคใช้ดู
Code (JavaScript)
//================================================
// Function : numericOnly
// Description : allows user to enter only numeric values in textbox
// Input : intType
//
// intType = 1 : used for numeric only values 0 to 9 only
// intType = 2 : allows '/' character usually intended for date text box "YYYY/MM/DD" type
// intType = 3 : allows '.' character usually intended for values with decimal
// intType = 4 : allows '-' character useally intended for zip or tel/fax
// intType = 5 : allows ':' character useally intended
// intType = 6 : allows '-' character useally intended for minus
// intType = 7 : allows '-','.' character usually intended for values with decimal or minus
//================================================
function numericOnly(obj, evnt, intType) {
var strVal;
var _keycode;
var _srcelement;
if(window.event) {
_keycode = window.event.keyCode;
_srcelement = window.event.srcElement.value;
}else {
_keycode = evnt.which;
_srcelement = obj.value;
}
if (_keycode < 48 || _keycode > 57) // 0 to 9
{
if(_keycode == 13){ //[_keycode == 13 is enter button]
return;
}
if (intType == 1){
if(window.event) {
window.event.keyCode = 0;
}else {
if( !(_keycode == 8 || _keycode == 0) ){
evnt.preventDefault();
}
return;
}
}
else
{
if((intType == 6 || intType == 7) && _keycode == 45 || _keycode == 0) {
strVal = _srcelement;
if(strVal.indexOf("-", 0)!=-1){
if(window.event) {
window.event.keyCode = 0;
}else {
evnt.preventDefault();
}
}
return;
}
if (_srcelement == '')
{
if(window.event) {
window.event.keyCode = 0;
}else {
evnt.preventDefault();
}
return;
}
if ((intType == 2 && _keycode == 47)){ // allows '/' character
strVal = _srcelement;
}
else if ((intType == 3 || intType == 7) && _keycode == 46 || _keycode == 0)
{
strVal = _srcelement;
if(strVal.indexOf('.',0) != -1) {
if(window.event) {
window.event.keyCode = 0;
}else {
evnt.preventDefault();
}
}
}
else if (intType == 4 && _keycode == 45 || _keycode == 0) // allows '-' character
return;
else if (intType == 5 && _keycode == 58 || _keycode == 0) // allows ':' character ACE Add
return;
else {
if(window.event) {
window.event.keyCode = 0;
}else {
if( !(_keycode == 8 || _keycode == 0) ){
evnt.preventDefault();
}
return;
}
}
}
}
}
|
|
|
|
|
Date :
2010-04-02 08:44:40 |
By :
newnakab |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|