|
 |
|
จาวาสคริปต์ เช็ค Form ไม่ทำงานช่วยดูหน่อยครับ ตัวอื่นถ้าไม่กรอกแบบฟอร์มมัน alert หมดยกเว้น 3 |
|
 |
|
|
 |
 |
|
ชื่อในช่อง form ตรงกันปะครับ ลองเอาโค๊ดมาแปะไว้ครับ
|
 |
 |
 |
 |
Date :
2010-03-09 14:42:04 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คัดมาทั้งหมดเลยครับ (ไม่ต้องสนใจ table นะครับ)
Code (PHP)
<form action="addnew.php" method="post" name ="checkForm" id="checkForm" onsubmit="return check()">
<tr>
<td height="20" colspan="2"><div align="left"><img src="images/PostAuthorIcon.png" width="14" height="14" /></div></td>
</tr>
<tr>
<td width="133"><div align="right" class="regist">ชื่อ-นามสกุล :</div></td>
<td width="337">
<input name="name" type="text" id="name" size="37.5" />
<span class="red">**</span></td>
</tr>
<tr>
<td class="regist"><div align="right">เพศ :</div></td>
<td><font size="2" face=" Tahoma, sans-serif">
<input name="sex" type="radio" value="ชาย" style="background-color:#94CDFF; color:#ffffff; CURSOR: default;"checked="checked" />
ชาย
<input name="sex" type="radio" style="background-color:#94CDFF; color:#ffffff; CURSOR: default;"value="หญิง" />
หญิง</font></td>
</tr>
<tr>
<td class="regist"><div align="right">อายุ :</div></td>
<td><div align="left"><font size="2" face="M Tahoma, sans-serif">
<input name="age" type="text" id="age" size="5" />
</font> <span class="red">**</span></div></td>
</tr>
<tr>
<td class="regist"><div align="right">จังหวัด : </div></td>
<td><div align="left">
<select name="province" id="province" >
<option value="" selected="selected">เลือกจังหวัด</option>
<option value="กระบี่">กระบี่ </option>
<option value="กรุงเทพมหานคร">กรุงเทพมหานคร</option>
<option value="กาญจนบุรี">กาญจนบุรี </option>
<option value="กาฬสินธุ์">กาฬสินธุ์ </option>
<option value="กำแพงเพชร">กำแพงเพชร </option>
<option value="ขอนแก่น">ขอนแก่น</option>
<option value="จันทบุรี">จันทบุรี</option>
<option value="ฉะเชิงเทรา">ฉะเชิงเทรา </option>
<option value="ชัยนาท">ชัยนาท </option>
<option value="ชัยภูมิ">ชัยภูมิ </option>
<option value="ชุมพร">ชุมพร </option>
<option value="ชลบุรี">ชลบุรี </option>
<option value="เชียงใหม่">เชียงใหม่ </option>
<option value="เชียงราย">เชียงราย </option>
<option value="ตรัง">ตรัง </option>
<option value="ตราด">ตราด </option>
<option value="ตาก">ตาก </option>
<option value="นครนายก">นครนายก </option>
<option value="นครปฐม">นครปฐม </option>
<option value="นครพนม">นครพนม </option>
<option value="นครราชสีมา">นครราชสีมา </option>
<option value="นครศรีธรรมราช">นครศรีธรรมราช </option>
<option value="นครสวรรค์">นครสวรรค์ </option>
<option value="นราธิวาส">นราธิวาส </option>
<option value="น่าน">น่าน </option>
<option value="นนทบุรี">นนทบุรี </option>
<option value="บุรีรัมย์">บุรีรัมย์</option>
<option value="ประจวบคีรีขันธ์">ประจวบคีรีขันธ์ </option>
<option value="ปทุมธานี">ปทุมธานี </option>
<option value="ปราจีนบุรี">ปราจีนบุรี </option>
<option value="ปัตตานี">ปัตตานี </option>
<option value="พะเยา">พะเยา </option>
<option value="พระนครศรีอยุธยา">พระนครศรีอยุธยา </option>
<option value="พังงา">พังงา </option>
<option value="พิจิตร">พิจิตร </option>
<option value="พิษณุโลก">พิษณุโลก </option>
<option value="เพชรบุรี">เพชรบุรี </option>
<option value="เพชรบูรณ์">เพชรบูรณ์ </option>
<option value="แพร่">แพร่ </option>
<option value="พัทลุง">พัทลุง </option>
<option value="ภูเก็ต">ภูเก็ต </option>
<option value="มหาสารคาม">มหาสารคาม </option>
<option value="มุกดาหาร">มุกดาหาร </option>
<option value="แม่ฮ่องสอน">แม่ฮ่องสอน </option>
<option value="ยโสธร">ยโสธร </option>
<option value="ยะลา">ยะลา </option>
<option value="ร้อยเอ็ด">ร้อยเอ็ด </option>
<option value="ระนอง">ระนอง </option>
<option value="ระยอง">ระยอง </option>
<option value="ราชบุรี">ราชบุรี</option>
<option value="ลพบุรี">ลพบุรี </option>
<option value="ลำปาง">ลำปาง </option>
<option value="ลำพูน">ลำพูน </option>
<option value="เลย">เลย </option>
<option value="ศรีสะเกษ">ศรีสะเกษ</option>
<option value="สกลนคร">สกลนคร</option>
<option value="สงขลา">สงขลา </option>
<option value="สมุทรสาคร">สมุทรสาคร </option>
<option value="สมุทรปราการ">สมุทรปราการ </option>
<option value="สมุทรสงคราม">สมุทรสงคราม </option>
<option value="สระแก้ว">สระแก้ว </option>
<option value="สระบุรี">สระบุรี </option>
<option value="สิงห์บุรี">สิงห์บุรี </option>
<option value="สุโขทัย">สุโขทัย </option>
<option value="สุพรรณบุรี">สุพรรณบุรี </option>
<option value="สุราษฎร์ธานี">สุราษฎร์ธานี </option>
<option value="สุรินทร์">สุรินทร์ </option>
<option value="สตูล">สตูล </option>
<option value="หนองคาย">หนองคาย </option>
<option value="หนองบัวลำภู">หนองบัวลำภู </option>
<option value="อำนาจเจริญ">อำนาจเจริญ </option>
<option value="อุดรธานี">อุดรธานี </option>
<option value="อุตรดิตถ์">อุตรดิตถ์ </option>
<option value="อุทัยธานี">อุทัยธานี </option>
<option value="อุบลราชธานี">อุบลราชธานี</option>
<option value="อ่างทอง">อ่างทอง </option>
<option value="อื่นๆ">อื่นๆ</option>
</select>
<span class="red">**</span></div></td>
</tr>
<tr>
<td class="regist"><div align="right">โทรศัพท์ :</div></td>
<td><div align="left">
<input name="phone" type="text" id="phone"size="22" />
<span class="red">**</span></div></td>
</tr>
<tr>
<td class="regist"><div align="right">E-mail :</div></td>
<td><div align="left">
<input name="email" type="text" id="email" size="22" />
<span class="red">**</span></div></td>
</tr>
<tr>
<td class="regist"><div align="right">วัน เดือน ปี ที่โอน :</div></td>
<td class="regist"><input name="year" type="text" id="year" size="40" value=ระบบจะลงให้อัตโนมัติตามวันเดือนปีปัจจุบัน></td>
</tr>
<tr>
<td class="regist"><div align="right">เวลาที่โอน : </div></td>
<td><input type="text" name="dtime" id="dtime"size="10" />
<span class="regist">น.
<span class="red">**</span></span></td>
</tr>
<tr>
<td class="regist"><div align="right">จำนวน :</div></td>
<td><input type="text" name="person" id="person"size="10" />
<span class="regist">คน.
<span class="red">**</span></span> </td>
</tr>
<tr>
<td class="regist"><div align="right">จำนวนเงิน :</div></td>
<td><input type="text" name="money" id="money"size="10" />
<span class="regist">บาท.
<span class="red">**</span></span></td>
</tr>
<tr>
<td class="regist"><div align="right">ธนาคาร :</div></td>
<td><font size="2" face=" Tahoma, sans-serif">
<input name="bank" type="radio" value="ไทยพาณิชย์" style="background-color:#94CDFF; color:#ffffff; CURSOR: default;"checked="checked" />
<img src="images/scb.gif" width="16" height="16" />
<input name="bank" type="radio" style="background-color:#94CDFF; color:#ffffff; CURSOR: default;"value="กสิกร" />
<img src="images/tfb.gif" width="16" height="16" /> </font></td>
</tr>
<tr>
<td class="regist"><div align="right">หมายเหตุอื่นๆ <br />
เช่น โอนด้วยวิธีใด :</div></td>
<td><textarea name="msg" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" style="background-color:#94CDFF; color:#ffffff; CURSOR: hand; " value="Submit" />
<input type="reset" name="Submit2"style="background-color:#94CDFF; color:#ffffff; CURSOR: hand; " value="Reset" />
</div></td>
</tr>
<script language="JavaScript" type="text/javascript">
function check() {
if(document.checkForm.name.value=="") {
alert("กรุณากรอกชื่อ-นามสกุลด้วยค่ะ") ;
document.checkForm.name.focus() ;
return false ;
}
else if(document.checkForm.age.value=="") {
alert("กรุณากรอกอายุด้วยค่ะ") ;
document.checkForm.age.focus() ;
return false ;
}else if(isNaN(document.checkForm.age.value)) {
alert("กรุณากรอกอายุด้วยตัวเลขเท่านั้นค่ะ") ;
document.checkForm.age.focus() ;
return false ;
}
else if(document.checkForm.province.selectedIndex==0) {
alert("กรุณาระบุจังหวัดที่ท่านอยู่ด้วยค่ะ") ;
return false ;
}
else if(document.checkForm.phone.value=="") {
alert("กรุณาใส่เบอร์โทรติดต่อด้วยค่ะ") ;
document.checkForm.phone.focus() ;
return false ;
}else if(isNaN(document.checkForm.phone.value)) {
alert("เบอร์โทรติดต่อต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.phone.focus() ;
return false ;
}
else if(document.checkForm.email.value=="") {
alert("กรุณากรอกอีเมล์ด้วยนะค่ะ") ;
return false ;
}
else if(checkForm.email.value.indexOf('@')==-1) {
alert("อีเมล์ของคุณไม่ถูกต้องค่ะ") ;
document.checkForm.email.focus() ;
return false ;
}
else if(checkForm.email.value.indexOf('.')==-1) {
alert("อีเมล์ของคุณไม่ถูกต้องค่ะ") ;
document.checkForm.email.focus() ;
return false ;
}
else if(document.checkForm.dtime.value=="") {
alert("กรุณาใส่เวลาที่โอนด้วยค่ะ") ;
document.checkForm.dtime.focus() ;
return false ;
}else if(isNaN(document.checkForm.dtime.value)) {
alert("เวลาที่โอนต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.dtime.focus() ;
return false ;
}
else if(document.checkForm.person.value=="") {
alert("กรุณาใส่จำนวนผู้สมัครด้วยค่ะ") ;
document.checkForm.person.focus() ;
return false ;
}else if(isNaN(document.checkForm.person.value)) {
alert("จำนวนผู้สมัครต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.person.focus() ;
return false ;
}
else if(document.checkForm.money.value=="") {
alert("กรุณาใส่จำนวนเงินด้วยค่ะ") ;
document.checkForm.money.focus() ;
return false ;
}else if(isNaN(document.checkForm.money.value)) {
alert("จำนวนเงินต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.money.focus() ;
return false ;
}
else
return true ;
}
</script>
</form>
|
 |
 |
 |
 |
Date :
2010-03-09 15:10:51 |
By :
com |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2010-03-10 16:53:05 |
By :
nuf4 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลืมใส่ document ตรงตรวจสอบ email ครับ
Code (PHP)
<script language="JavaScript" type="text/javascript">
function check() {
if(document.checkForm.name.value=="") {
alert("กรุณากรอกชื่อ-นามสกุลด้วยค่ะ") ;
document.checkForm.name.focus() ;
return false ;
}
else if(document.checkForm.age.value=="") {
alert("กรุณากรอกอายุด้วยค่ะ") ;
document.checkForm.age.focus() ;
return false ;
}else if(isNaN(document.checkForm.age.value)) {
alert("กรุณากรอกอายุด้วยตัวเลขเท่านั้นค่ะ") ;
document.checkForm.age.focus() ;
return false ;
}
else if(document.checkForm.province.selectedIndex==0) {
alert("กรุณาระบุจังหวัดที่ท่านอยู่ด้วยค่ะ") ;
return false ;
}
else if(document.checkForm.phone.value=="") {
alert("กรุณาใส่เบอร์โทรติดต่อด้วยค่ะ") ;
document.checkForm.phone.focus() ;
return false ;
}else if(isNaN(document.checkForm.phone.value)) {
alert("เบอร์โทรติดต่อต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.phone.focus() ;
return false ;
}
else if(document.checkForm.email.value=="") {
alert("กรุณากรอกอีเมล์ด้วยนะค่ะ") ;
return false ;
}
else if(document.checkForm.email.value.indexOf('@')==-1) {
alert("อีเมล์ของคุณไม่ถูกต้องค่ะ") ;
document.checkForm.email.focus() ;
return false ;
}
else if(document.checkForm.dtime.value=="") {
alert("กรุณาใส่เวลาที่โอนด้วยค่ะ") ;
document.checkForm.dtime.focus() ;
return false ;
}else if(isNaN(document.checkForm.dtime.value)) {
alert("เวลาที่โอนต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.dtime.focus() ;
return false ;
}
else if(document.checkForm.person.value=="") {
alert("กรุณาใส่จำนวนผู้สมัครด้วยค่ะ") ;
document.checkForm.person.focus() ;
return false ;
}else if(isNaN(document.checkForm.person.value)) {
alert("จำนวนผู้สมัครต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.person.focus() ;
return false ;
}
else if(document.checkForm.money.value=="") {
alert("กรุณาใส่จำนวนเงินด้วยค่ะ") ;
document.checkForm.money.focus() ;
return false ;
}else if(isNaN(document.checkForm.money.value)) {
alert("จำนวนเงินต้องเป็นตัวเลขเท่านั้นค่ะ") ;
document.checkForm.money.focus() ;
return false ;
}
else
return true ;
}
</script>
|
 |
 |
 |
 |
Date :
2010-03-11 11:20:23 |
By :
jeabz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนจากระบุชื่อ form มาเป็นแบบนี้ดูซิ documentforms[0].name.value
|
 |
 |
 |
 |
Date :
2010-03-14 21:52:05 |
By :
dekcomsci |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|