作者shiengchyi (風真大耶)
看板Web_Design
標題[問題] JavaScript 表單傳送問題
時間Thu Nov 30 16:55:16 2006
html部份:
<table border="0" width="35%" height="100%">
<form action="login.php" method="POST" name="login_form">
<tr><td>
帳號:<input type="text" size="35" maxlength="35" name="account">
</td></tr>
<tr>
<td>
密碼:<input type="password" size="39" maxlength="39" name="password">
</td>
</tr>
<tr><td align="center">
<input type="reset" value="清除">
<input type="button" name="sub" value="登入" onClick="chk()">
^^^^^^^呼叫chk()
</td></tr>
</form>
<tr><td align="middle">
<a href="register.php">我要註冊</a>
</td></tr>
</table>
javascript部分:
function chk()
{
if(document.login_form.account.value.length==0)
{
alert("請輸入帳號!");
return ;
}
if(document.login_form.password.value.length==0)
{
alert("請輸入密碼!");
return ;
}
document.login_form.submit();
}
php部分:
$sub=$_POST['sub'];
可是我這樣寫...$sub 抓不到數值....>"<
有爬過文...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.131.136.203
1F:推 grence:是我眼花嗎..form裡面又沒有叫sub的元件..囧a 11/30 17:14
2F:→ grence:PHP裡用$_POST['ACCOUNT']跟$_POST['PASSWORD']抓變數 11/30 17:15
3F:推 shiengchyi:有呀...登入的那一個按鈕就叫sub.... 11/30 17:23
4F:→ grence:果然眼花,但$_POST['']要抓的仍然不是那個按鈕 11/30 17:27
5F:推 shiengchyi:所以我想問是為什麼抓不到?? 11/30 17:32
6F:→ shiengchyi:其他都抓的到 唯獨sub 抓不到... 11/30 17:33
7F:推 superGA:JS就是這樣 用JS傳form 他不會理button跟submit兩個type 11/30 19:38
8F:→ superGA:這兩個值 本來使用者就不能輸入 所以也沒必要傳 11/30 19:40
9F:→ superGA:你可以試試看把button改成text 然後click他 ...= =" 11/30 19:41
10F:推 shiengchyi:我找到解決方法了...另外使用hidden來傳值判斷 11/30 20:09
11F:→ grence:看來又搞錯問題,回錯答案...orz 12/01 14:31