回答編集履歴

2

修正版

2019/10/31 04:24

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -57,3 +57,59 @@
57
57
  </form>
58
58
 
59
59
  ```
60
+
61
+
62
+
63
+ # 修正版
64
+
65
+ ```javascript
66
+
67
+ <script>
68
+
69
+ window.addEventListener('DOMContentLoaded', ()=>{
70
+
71
+ const f1=[].map.call(document.querySelectorAll('#form1 [type=checkbox]'),x=>x);
72
+
73
+ const f2=[].map.call(document.querySelectorAll('#form2 [type=text]'),x=>x);
74
+
75
+ f1.forEach(x=>x.addEventListener('change',()=>{
76
+
77
+ const idx=f1.indexOf(x);
78
+
79
+ f2[idx].disabled=!x.checked;
80
+
81
+ }));
82
+
83
+ f2.forEach(x=>x.disabled=true);
84
+
85
+ });
86
+
87
+ </script>
88
+
89
+ <form id="form1">
90
+
91
+ <input type="checkbox" name="hoge[]" value="data1-1">
92
+
93
+ <input type="checkbox" name="hoge[]" value="data1-2">
94
+
95
+ <input type="checkbox" name="hoge[]" value="data1-3">
96
+
97
+ <div id="getData">GET</div>
98
+
99
+ </form>
100
+
101
+
102
+
103
+ <form id="form2">
104
+
105
+ <input type="text" name="hoge2[]" value="data2-1">
106
+
107
+ <input type="text" name="hoge2[]" value="data2-2">
108
+
109
+ <input type="text" name="hoge2[]" value="data2-3">
110
+
111
+ <input type="submit" value="送信">
112
+
113
+ </form>
114
+
115
+ ```

1

sample

2019/10/31 04:24

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -3,3 +3,57 @@
3
3
  むしろ別のフォームで送信する意味はないと思います
4
4
 
5
5
  送信しないフォームはなんのためにあるのでしょうか?
6
+
7
+
8
+
9
+ # sample
10
+
11
+ ```javascript
12
+
13
+ <script>
14
+
15
+ window.addEventListener('DOMContentLoaded', ()=>{
16
+
17
+ const f1=[].map.call(document.querySelectorAll('#form1 [type=checkbox]'),x=>x);
18
+
19
+ const f2=[].map.call(document.querySelectorAll('#form2 [type=checkbox]'),x=>x);
20
+
21
+ f1.forEach(x=>x.addEventListener('change',()=>{
22
+
23
+ const idx=f1.indexOf(x);
24
+
25
+ f2[idx].checked=x.checked;
26
+
27
+ }));
28
+
29
+ });
30
+
31
+ </script>
32
+
33
+ <form id="form1">
34
+
35
+ <input type="checkbox" name="hoge1" value="data1-1">
36
+
37
+ <input type="checkbox" name="hoge1" value="data1-2">
38
+
39
+ <input type="checkbox" name="hoge1" value="data1-3">
40
+
41
+ <div id="getData">GET</div>
42
+
43
+ </form>
44
+
45
+
46
+
47
+ <form id="form2" action="hogehoge" method="post">
48
+
49
+ <input type="checkbox" name="hoge2" value="data2-1" readonly>
50
+
51
+ <input type="checkbox" name="hoge2" value="data2-2" readonly>
52
+
53
+ <input type="checkbox" name="hoge2" value="data2-3" readonly>
54
+
55
+ <input type="submit" value="送信">
56
+
57
+ </form>
58
+
59
+ ```