teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

加筆修正

2015/10/22 03:52

投稿

退会済みユーザー
answer CHANGED
@@ -1,3 +1,30 @@
1
+ ```html
2
+ <input type="submit" value="ログイン" onclick="actionA();"/><br />
3
+ <input type="submit" value="新規登録" onclick="actionB();"/><br />
4
+ ```
5
+
6
+ ```html
7
+ <input type="button" value="ログイン" onclick="actionA();"/><br />
8
+ <input type="button" value="新規登録" onclick="actionB();"/><br />
9
+ <input type="hidden" name="a_or_b" value="" /><br />
10
+ ```
11
+ にして、
12
+ ```javascript
13
+ $(".btn").on("click", function actionA(){
14
+ document.getElementById("form").action = "./mail.html";
15
+ ```
16
+
17
+ ```javascript
18
+ $(".btn").on("click", function actionA(){
19
+ document.form.action = "./mail.html";
20
+ document.form.a_or_b.value = "a";
21
+ ...
22
+ ...
23
+ document.form.submit();
24
+ }
25
+ ```
26
+ みたいにする感じですが、いかがでしょうか。
27
+ ---
1
28
  例えば、隠し送信パラメータ`<input type="hidden" name="a_or_b" />`に、AボタンBボタンのどれを押したかを示す値を納めてからsubmitしてはいかがでしょうか。
2
29
  あわせて、`<input type="submit" ~onclick="" />`はすべて`<input type="button" ~onclick="" />`にしましょう。
3
- `dcument.getElementById("form").submit();`にてフォーム送信できますので。
30
+ `document.getElementById("form").submit();`にてフォーム送信できますので。