tes.htm
1<!-- #include file="message.inc" -->
2<HTML>
3<KEPALA>
4<TITLE> Dokumen Baru </TITLE>
5 <meta http-equiv="content-type" content="text/html; charset=shift_jis" />
6 <meta http-equiv="pragma" content="tanpa-cache">
7 <meta http-equiv="cache-control" content="no-cache">
8 <meta http-equiv="kedaluwarsa" content="0">
9<skrip src="common.js"></skrip>
10<skrip src="validate.js"></skrip>
11
12</KEPALA>
13
14<TUMBUH>
15<METODE BENTUK=PASCA TINDAKAN="">
16ID<INPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",<%=IMSG0002%>" ><br>
17ID<INPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",<%=IMSG0002%>" ><br>
18ID<INPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",<%=IMSG0002%>" ><br>
19ID<INPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",<%=IMSG0002%>" ><br>
20
21名称<INPUT TYPE="text" id="txtString" NAME="txtString" maxlength="5" feildtype="string" msg="<%=IMSG0003%>,<%=IMSG0004%>" mustitem="true "><br>
22名称<INPUT TYPE="text" id="txtString" NAME="txtString" maxlength="5" feildtype="string" msg="<%=IMSG0003%>,<%=IMSG0004%>" mustitem="true "><br>
23名称<INPUT TYPE="text" id="txtString" NAME="txtString" maxlength="5" feildtype="string" msg="<%=IMSG0003%>,<%=IMSG0004%>" mustitem="true "><br>
24
25名称2<INPUT TYPE="text" id="txtStr" NAME="txtStr" maxlength="5" feildtype="string" msg="<%=IMSG0003%>,<%=IMSG0004%>" mustitem=" benar"><br>
26<INPUT TYPE="button" value="kirim" onclick="validate(); return false;">
27<BAHASA SKRIP="JavaScript">
28<!--
29//validasi()
30//-->
31</SKRIP>
32</BENTUK>
33</BODI>
34</HTML>
35
validasi.js
1fungsi memvalidasi(){
2
3 //var objs = dokumen.semua;
4 //var Elements = dokumen.getElementsByTagName("*");
5 elemen var;
6 var ctlArray;
7 var ctlArrayName;
8 var saya, j;
9 var elLen, arrLen;
10 var pesan;
11
12 Elemen = document.getElementsByTagName("input");
13 arrNama = "";
14
15 untuk ( i dalam Elemen ) {
16 elLen = Elemen[i].panjang;
17
18 jika (elLen > 1) {
19 ctlArray = Elemen[i];
20 arrLen = ctlArray.panjang;
21
22 jika (arrName != ctlArray[0].nama) {
23 arrName = ctlArray[0].nama;
24
25 untuk (j=0; j < arrLen; j++) {
26 jika (checkValue(ctlArray[j]) == false) {
27 mengembalikan salah;
28 }
29 }
30
31 }
32
33 }lainnya{
34
35 if (checkValue(Elemen[i]) == false) {
36 mengembalikan salah;
37 }
38 }
39 }
40
41 mengembalikan nilai benar;
42}
43
44fungsi checkValue (obj){
45
46 var len;
47 len = obj.maxLength;
48
49 if ( obj.type == "teks" ) {
50
51 //if (obj.msg != tidak terdefinisi ) {
52 jika ( obj.msg ) {
53 pesan = obj.msg.split(",");
54 } lain {
55 mengembalikan nilai benar;
56 }
57
58 if ( trim(obj.value) == "" && obj.mustitem && obj.mustitem == "true") {
59 peringatan(pesan[0]);
60 getFocusSelect(obj);
61 mengembalikan salah;
62 }lainnya {
63
64 if ( trim(obj.value) != ""&& obj.feildtype && obj.feildtype == "integer" ) {
65
66 jika ( checkNumLen(obj.value, len) == false ) {
67 peringatan(pesan[1]);
68 getFocusSelect(obj);
69 mengembalikan salah;
70 }
71
72 } else if ( trim(obj.value) != "" && obj.feildtype && obj.feildtype == "string" ) {
73
74 if ( getLenthByByte(trim(obj.value)) > len){
75 peringatan(pesan[1]);
76 getFocusSelect(obj);
77 mengembalikan salah;
78 }
79 }
80 }
81 }
82
83}
pesan.inc 1<%
2Const IMSG0001 = "ID必须输入!"
3Const IMSG0002 = "ID输入格式错误!"
4Const IMSG0003 = "名称必须输入!"
5Const IMSG0004 = "名称输入格式错误!"
6%>
http://www.cnblogs.com/meil/archive/2007/04/05/700772.html