[請益] 表單驗證...

看板PHP作者 (小雷)時間13年前 (2010/08/20 17:34), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/1
小的又來求救了@@ <form name="msg_form" action="show/msg.php" method="post" onsubmit="msg_check()"> ~~~ 一些欄位 ~~~~~ <input name="msg_send" type="submit" value="寄 出" /> </form> msg_check() --->是另一個php黨 是判斷msg_form的欄位是否為空然後return回來 以下是msg_check的程式碼.... <script type="text/javascript"> function msg_check(){ if(document.msg_form.msg_name.value==""){ alert("尚未輸入姓名"); return false; } else{ return true; } } </script> 但是我按下"寄出"之後 是跳出了"尚未輸入姓名" return回來之後 他就將表單送出去了 照理說應該是return false 而表單不會送出吧~"~ 怎麼會這樣 請教前輩!! -- 活在我不懂的道理 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.64.102.55

08/20 18:13, , 1F
丟水球不理我 = =+
08/20 18:13, 1F

08/20 18:14, , 2F
把 input type 改成 botton , JS 加入 submit();
08/20 18:14, 2F

08/20 18:22, , 3F
嘖 ... 我看錯了 ~"~
08/20 18:22, 3F

08/20 18:27, , 4F
onsubmit 改成 onsubmit="return msg_check();"
08/20 18:27, 4F
文章代碼(AID): #1CRan2dF (PHP)