งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

ASP [#12] ตัวอย่าง VBScript เพื่อใช้ตรวจสอบค่าบนฟอร์ม

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "ASP [#12] ตัวอย่าง VBScript เพื่อใช้ตรวจสอบค่าบนฟอร์ม"— ใบสำเนางานนำเสนอ:

1 ASP [#12] ตัวอย่าง VBScript เพื่อใช้ตรวจสอบค่าบนฟอร์ม
การใช้ Java script ยืนยันการลบข้อมูล การตรวจสอบอีเมลล์ด้วย java script การใช้ JavaScript ตรวจสอบให้โปรแกรมสามารถกรอกได้เฉพาะภาษาไทย

2 ตัวอย่าง VBScript การใช้ Message Box เพื่อแจ้งเตือนผู้ใช้ฝั่ง Client ด้วย VBScript

3 VBScript ให้แทรกไว้ก่อนที่จะเรียกใช้
Sam12-1.asp <Script Language="VBScript"> <!-- Sub FillBlank_Onclick() if document.form1.nickname.Value="" then MsgBox("กรุณาป้อนชื่อ") document.form1.Nickname.Focus elseif IsNumeric(document.form1.Nickname.Value)=True then MsgBox("กรุณาป้อนชื่อเป็นตัวอักษร") else document.form1.Submit end if End sub --> </Script> ต้องตั้งชื่อตัวแปรให้ตรงกับฟอร์ม Sub Nickname_onFocus() document.form1.nickname.Value= "นายกอ" End sub

4 ในไฟล์เดียวกันให้แทรก tag ของ form ลงไป
Sam12-1.asp <form name="form1" method="post" action=""> <p> Nickname: <input type="text" name"="Nickname"> </p> <p> Detail : <textarea name="Detail"></textarea> <input type="button" name=FillBlank value="Button"> </p> <p>  </p> </form>

5 แบบฝึกหัด เมื่อเลือกรายการเดือนที่เป็นตัวเลขแล้วแล้ว
ให้แสดงเดือนไทยในช่องด้านล่าง..ทันที โดยไม่ต้องกด submit เดือน :: 5 ชื่อเดือนไทย :: พฤษภาคม SUBMIT

6 การใช้ Javascript ยืนยันการลบข้อมูลใน DB
สร้างฐานข้อมูลใน Ms-Access ตั้งชื่อ mydatabase.mdb ตารางชื่อ Month เก็บไฟล์ไว้ที่ห้อง DB

7 การใช้ Javascript ยืนยันการลบข้อมูล
<html> <body bgcolor="#FFFFFF"> <% Set Connect_DB=Server.CreateObject("ADODB.Connection") Connect_DB.Open "Driver=Microsoft Access Driver (*.mdb);DBQ="& Server.MapPath("db/mydatabase.mdb") %> <table width="33%" border="1" cellspacing="0" cellpadding="0" height="27" name="5"> <tr> <td height="23" width="18%"> <div align="center">id</div> </td> <td height="23" width="66%"> <div align="center">เดือน</div> </td> <td height="23" width="16%"> <div align="center">ลบ</div> </td> </tr> </table> <%sql="Select * from month" Set Rs=Connect_DB.execute(sql) while Not Rs.EOF%> <table width="33%" border="1" cellspacing="0" cellpadding="0" height="27" name="5"> <tr> <td height="23" width="18%"> <div align="center"> Sam12-2.asp

8 Sam12-2.asp (ต่อ) <script language="JavaScript"> function Conf<% =Rs("id")%>(object) { if (confirm("ยืนยันการลบข้อมูลเดือน [ <% =Rs("month")%> ] ") ==true) { return true; } return false; } </script> <% =Rs("id")%> </div> </td> <td height="23" width="66%"> <% =Rs("month")%> </td> <td height="23" width="16%"> <div align="center"> <a href="Sam12-3.asp?id=<%=Rs("id") %>" onClick="return Conf<%=Rs("id") %>(this)">ลบ</a> </div> </td> </tr> </table> <%Rs.MoveNext wend %> </body> </html>

9 Sam12-3.asp <% On Error Resume Next Set Connect_DB=Server.CreateObject("ADODB.Connection") Connect_DB.Open "Driver=Microsoft Access Driver (*.mdb);DBQ="& Server.MapPath("db/mydatabase.mdb") Sql1="DELETE * FROM month WHERE id="&Request.QueryString("id") Connect_DB.Execute(sql1) Response.Redirect("Sam12-2.asp") %>

10 การตรวจสอบอีเมลล์ด้วย java script
<script language="JavaScript"> <!-- Begin function checkFields2() { missinginfo = ""; if (document.regis.name.value == "") { missinginfo += "\n - * ชื่อ"; } if ((document.regis. .value == "") || == -1) || (document.regis. .value.indexOf('.') == -1)) { missinginfo += "\n - * อีเมลล์"; } if (document.regis.topic_s.value == "") { missinginfo += "\n - * หัวข้อ "; } if (document.regis.comment.value == "") { missinginfo += "\n - * รายละเอียด"; } if (missinginfo != "") { missinginfo ="_____________________________\n" + "ท่านกรอกข้อมูลไม่ถูกต้องในช่องต่อไปนี้ :\n" + missinginfo + "\n_____________________________" + "\nกรุณากลับไปกรอกอีกครั้ง "; alert(missinginfo); return false; } else return true; } // End --> </script> Sam12-4.ASP

11 <form method="POST" action="" name="regis" onSubmit="return checkFields2();" > <table width="96%" border="0" align="center" cellpadding="3" cellspacing="2"> <tr> <td width="4%"> </td> <td width="20%"> </td> <td width="3%"> </td> <td width="73%"> </td> </tr> <tr> <td width="4%"> </td> <td width="20%">ชื่อ </td> <td width="3%"> </td> <td width="73%"> <input type="text" name="name" maxlength="40"> </td> </tr> <tr> <td width="4%" height="31"> </td> <td width="20%" height="31">อีเมลล์</td> <td width="3%" height="31"> </td> <td width="73%" height="31"> <input type="text" name=" " maxlength="45"> </td> </tr> <tr> <td width="4%" height="21"> </td> <td width="20%" height="21">หัวข้อ</td> <td width="3%" height="21"> </td> <td width="73%" height="21"> <input type="text" name="topic_s" size="40" maxlength="250"> </td> </tr> <tr> <td width="4%" height="21"> </td> <td width="20%" height="21">รายละเอียด</td> <td width="3%" height="21"> </td> <td width="73%" height="21"> <textarea name="comment" cols="40" rows="6"></textarea> </td> </tr> <tr> <td width="4%"> </td> <td width="20%"> </td> <td width="3%"> </td> <td width="73%">  </td> </tr> <tr> <td width="4%"> </td> <td width="20%"> </td> <td width="3%"> </td> <td width="73%"> <input type="submit" name="Submit" value="ส่งข้อความ "> <input type="reset" name="Submit2" value="เขียนใหม่ "> </td> </tr> </table> </form>

12 การใช้ JavaScript ตรวจสอบให้โปรแกรมสามารถกรอกได้เฉพาะภาษาไทย
<script language="JavaScript"> function check_thai(ch){ var len, digit; if(ch == " "){ len=0; }else{ len = ch.length; } for(var i=0 ; i<len ; i++) { digit = ch.charAt(i) if(!((digit >= "a" && digit <= "z") || (digit >="0" && digit <="9") || (digit >="A" && digit <="Z"))){ ; }else{ return false; } } return true; } Sam12-5.ASP

13 การใช้ JavaScript ตรวจสอบให้โปรแกรมสามารถกรอกได้เฉพาะภาษาไทย (ต่อ)
Sam12-5.ASP function checkvalue() { if(!check_thai(document.fThai.n.value) || document.fThai.n.value == "" ) { alert('Please Enter Text Thai Only'); return false; }else{return true;} } </script> <form name="fThai" method="post" action="" onSubmit="return checkvalue()"> Number <input name="n" type="text" id="n"> <input type="submit" name="Submit" value="Submit"> </form>


ดาวน์โหลด ppt ASP [#12] ตัวอย่าง VBScript เพื่อใช้ตรวจสอบค่าบนฟอร์ม

งานนำเสนอที่คล้ายกัน


Ads by Google