ช่วยดูจาวาสคริปหนูหน่อยค่า มันไม่ทำงานอ่ะ

<!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>Untitled Document</title>
<script>
function test(type,idform){
    data = documemt.getElementById(idform).value;
   
    if(type=="engData"){
        for(i=0;i<data.length;i++){
            if(data.substring(i)=>
'a'&&data.substring(i)<='z'||data.substring(i)=>'0'&&data.substring(i)<='9'){
                   alert("ข้อมูลถูกต้อง");
            }else alert("ข้อมูลไม่ถูกต้อง");       
        }
    }   
}
</script>

</head>

<body>
<form>
<input name="nameeng" type="text" id="nameeng" size="70" onblur = "test('engData',nameeng);"/><span id="namethai_s"></span>
</form>
</body>
</html>

คือว่าทำมัยมันรันไม่ได้อ่ะค่ะ พอใส่ for กับ if เข้าไป alert มันก็ไม่ทำงานแล้วอ่ะค่ะ
แล้วถ้าจะเปลี่ยนจาก alert ให้ผลลัทพ์ที่ไปขึ้นตรง span หลังฟอร์มจะต้องเขียนยังไงค่ะ
19 เม.ย. 2552 8 2,793

แก้บรรทัดนี้ data = documemt.getElementById(idform).value
ตรง
document แล้วกะยังไม่ได้อ่ะจ๊ะ

#1

ตอบไม่ถูกเลยครับ คำสั่งมันผิดนะครับ
<script> ต้องเขียนแบบ <script language="JavaScript">
substring ใน js ไม่มีครับ ใช้ split
 งง ครับ
#2

คือว่ามันเขียน <script> งี้เฉยๆก็ได้ไม่ใช่หรือค่ะ? หรือจำเป็นต้องเขียนเต็มง่ะ - -?
ส่วน
substring ตัวนี้มีค่ะ มันใช้แทน substr ได้ค่ะ
แต่ไม่ค่อยนิยม เพราะใช้
substr กันมากกว่าอ่ะค่ะ

แต่ๆ ทะมัยใส่อีฟแล้วมันไม่ขึ้น
alert อ่ะ
แก้ไม่หายงิ

รบกวนผู้รู้ด้วยค่ะ งง


#3

งมสำเร็จแล้วค่าาา
#4

เย้ เช็คไทย-อังกฤษ ได้แย้ว ใส่ลง span ได้แล้วด้วย อิอิ
เอามาแจก เขียนได้ยุ่งดีไหมค่ะ -*-

<script language="javascript">
<!--
function test(type,idform){
    var data = document.getElementById(idform).value;
    var check = true;
    if(type=="engData"){
        for(i=0;i<data.length;i++){
            if(data.charAt(i)>
='a'&&data.charAt(i)<='z'||data.charAt(i)>='A'&&data.charAt(i)<='Z'||data.charAt(i)>='0'&&data.charAt(i)<='9'||data.charAt(i)==' '){
                check = true;
            }else{    
                check = false;
                break;
            }   
        }
        if(check==true){
            document.getElementById('namethai_s').innerHTML = "ข้อมูลถูกต้อง";
        }else if(check==false){
            document.getElementById('namethai_s').innerHTML = "กรุณากรอกภาษาอังกฤษเท่านั้น";
        }
    }else if(type=="thaiData"){
        for(i=0;i<data.length;i++){
            if(data.charAt(i)>
='ก'&&data.charAt(i)<='ฮ'||data.charAt(i)>='ฯ'&&data.charAt(i)<='ฺ'||data.charAt(i)>='เ'&&data.charAt(i)<='ํ'||data.charAt(i)>='๐'&&data.charAt(i)<='๙'||data.charAt(i)>='0'&&data.charAt(i)<='9'||data.charAt(i)==' '){
                check = true;
            }else{    
                check = false;
                break;
            }
        }
        if(check==true){
            document.getElementById('namethai_s').innerHTML = "ข้อมูลถูกต้อง";
        }else if(check==false){
            document.getElementById('namethai_s').innerHTML = "กรุณากรอกภาษาไทยเท่านั้น";
        }
    /*}else if(type=="telephone"){
   
    }else if(type=="mail")*/

   
    }else document.getElementById('namethai_s').innerHTML = "ไม่อยู๋ในเงื่อนไข";
}
//-->

</script>

</head>

<body>
<form>
<input name="nameeng" type="text" id="nameeng" size="70" onblur = "test('thaiData','nameeng');"/><span id="namethai_s">อะไรอ่ะ</span>
</form>
</body>
</html>
#5

สงสัยต่อนิสนุง

<from id = ' ' action=' ' onclick=' '>
<input type='Submit' >

รูปแบบนี้ ถ้ากดปุ่มแล้ว ระหว่าง action=' ' กับ onclick=' '  ใครทำงานก่อนกัน หรือมันทำงานพร้อมกันง่ะ งง
#6

555++++

ทำงานด้วยเหรอ

สำหรับฟอร์ม น่าจะเป็น onsubmit นะ

และ onsubmit จะทำงานก่อน action
#7

แหะๆ
ขอบคุณค่ะ


#8
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^