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

質問編集履歴

4

修正

2018/08/30 04:40

投稿

moppu
moppu

スコア9

title CHANGED
File without changes
body CHANGED
@@ -172,4 +172,81 @@
172
172
  window.onload = entryChange1;
173
173
  </script>
174
174
 
175
- ```
175
+ ```
176
+
177
+ ###追記(20180830) 解決したソース
178
+ ```html
179
+ <form class="form-control" action="./score" method="post">
180
+ <div>
181
+ <span>登録種別</span>
182
+ <label><input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />ユーザー</label>
183
+ <label><input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />チーム</label>
184
+ </div>
185
+
186
+ <div id="entry_as_user" class="form_contents">
187
+ <label>ユーザ名:
188
+ <input type="text" class="form-control" placeholder="ユーザー名"/>
189
+ </label>
190
+ <label>チーム名:
191
+ <select class="custom-select">
192
+ <option selected>チーム選択</option>
193
+ <option value="1">A-team</option>
194
+ <option value="2">B-team</option>
195
+ <option value="3">C-team</option>
196
+ <option value="4">D-team</option>
197
+ <option value="5">E-team</option>
198
+ </select>
199
+ </label>
200
+ <button type="submit">SUBMIT_A</button>
201
+ </div>
202
+
203
+ <div id="entry_as_team" class="form_contents">
204
+ <label>チーム名:
205
+ <input type="text" class="form-control" placeholder="チーム名"/>
206
+ </label>
207
+ <label>ユーザ名:
208
+ <select class="custom-select">
209
+ <option selected>ユーザー選択</option>
210
+ <option value="1">User-A</option>
211
+ <option value="2">User-B</option>
212
+ <option value="3">User-C</option>
213
+ <option value="4">User-D</option>
214
+ <option value="5">User-E</option>
215
+ </select>
216
+ </label>
217
+ <button type="submit">SUBMIT_B</button>
218
+ </div>
219
+ </form>
220
+
221
+ <!--スクリプト-->
222
+ <script type="text/javascript">
223
+ function entryChange1(){
224
+ var eau = document.getElementById('entry_as_user');
225
+ var eat = document.getElementById('entry_as_team');
226
+
227
+ radio = document.getElementsByName('entryPlan')
228
+ if(radio[0].checked) {
229
+ //フォーム
230
+ eau.style.display = "";
231
+ eat.style.display = "none";
232
+ //特典
233
+ //document.getElementById('firstNotice').style.display = "";
234
+ }else if(radio[1].checked) {
235
+ //フォーム
236
+ eau.style.display = "none";
237
+ eat.style.display = "";
238
+ //特典
239
+ //document.getElementById('firstNotice').style.display = "none";
240
+ }
241
+ }
242
+
243
+ //オンロードさせ、リロード時に選択を保持
244
+ window.onload = entryChange1;
245
+ </script>
246
+ ```
247
+ ```css
248
+ .form_contents >label{
249
+ display: block;
250
+ }
251
+ ```
252
+ 以上のソースコードを用いることで当初の期待値である、ラジオボタンごとのフォームの切り替え及び登録ボタンの差し替えが可能になりました。

3

変更点を追加し、問題点を記述しました

2018/08/30 04:40

投稿

moppu
moppu

スコア9

title CHANGED
File without changes
body CHANGED
@@ -78,7 +78,98 @@
78
78
 
79
79
  ```
80
80
 
81
- ### 試したこと
81
+ ### 変更後の問題点
82
+ フォームを2つずつ表示させたいのですが <tr>が一つにしかかからない為、ラジオボタンを切り替えても、フォームが3つ表示され切り替わらない。
82
83
 
84
+ ###変更後ソース
85
+
86
+ ```html
87
+ <!--インデント整えたバージョン-->
88
+
89
+ <form class="form-control" action="./score" method="post">
90
+ <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
91
+ <tr>
92
+ <th>登録種別</th>
93
+ <td>
94
+ <label>
95
+ <input type="radio" name="entryPlan" value="hoge1" onclick="entryChange1();" checked="checked" />
96
+ ユーザー
97
+ </label>
98
+ <label>
99
+ <input type="radio" name="entryPlan" value="hoge2" onclick="entryChange1();" />
100
+ チーム
101
+ </label>
102
+ </td>
103
+ </tr>
104
+ <!-- 表示非表示切り替え -->
105
+ <tr><!-- ←追加分-->
106
+ <tr id="firstBox">
107
+ <!--<tr> ←削除分-->
108
+ <th>ユーザー名:</th>
109
+ <td><input type="text" class="form-control" placeholder="ユーザー名"/></td>
110
+ </tr>
111
+ <tr>
112
+ <th>チーム名:</th>
113
+ <td>
114
+ <select class="custom-select">
115
+ <option selected>チーム選択</option>
116
+ <option value="1">A-team</option>
117
+ <option value="2">B-team</option>
118
+ <option value="3">C-team</option>
119
+ <option value="4">D-team</option>
120
+ <option value="5">E-team</option>
121
+ </select>
122
+ </td>
123
+ <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
124
+ </tr>
125
+ </tr>
126
+ <!-- 表示非表示切り替え -->
127
+ <tr><!-- ←追加分-->
128
+ <tr id="secondBox">
129
+ <!--<tr> ←削除分-->
130
+ <th>チーム名:</th>
131
+ <td><input type="text" class="form-control" placeholder="チーム名"/></td>
132
+ </tr>
133
+ <tr>
134
+ <th>ユーザー名:</th>
135
+ <td>
136
+ <select class="custom-select">
137
+ <option selected>ユーザー選択</option>
138
+ <option value="1">User-A</option>
139
+ <option value="2">User-B</option>
140
+ <option value="3">User-C</option>
141
+ <option value="4">User-D</option>
142
+ <option value="5">User-E</option>
143
+ </select>
144
+ </td>
145
+ <!-- <p>紹介された方のお名前を入力してください。</p></td> -->
146
+ </tr>
147
+ </tr>
148
+
149
+ </table>
150
+ </form>
151
+
152
+ <!--スクリプト-->
153
+ <script type="text/javascript">
154
+ function entryChange1(){
155
+ radio = document.getElementsByName('entryPlan')
156
+ if(radio[0].checked) {
157
+ //フォーム
158
+ document.getElementById('firstBox').style.display = "";
159
+ document.getElementById('secondBox').style.display = "none";
160
+ //特典
83
- http://5am.jp/javascript/form_change_javascript/
161
+ //document.getElementById('firstNotice').style.display = "";
162
+ }else if(radio[1].checked) {
163
+ //フォーム
164
+ document.getElementById('firstBox').style.display = "none";
165
+ document.getElementById('secondBox').style.display = "";
84
- 参考にしたサイトです
166
+ //特典
167
+ //document.getElementById('firstNotice').style.display = "none";
168
+ }
169
+ }
170
+
171
+ //オンロードさせ、リロード時に選択を保持
172
+ window.onload = entryChange1;
173
+ </script>
174
+
175
+ ```

2

質問を修正しました

2018/08/29 00:35

投稿

moppu
moppu

スコア9

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,10 @@
1
- ### 前提・実現したいこと
1
+ ### 前提
2
- 現在cakePHP3を使い開発をしている途中です。
2
+ 現在cakePHP3を使い、簡単なwebサイト作成していす。
3
- 期待値としては、チームを選択すると、チーム名と登録ユーザーが選べるフォームに切り替わることです。
4
3
 
4
+ ###期待値
5
+ ユーザーとチームの登録ページを作成しているのですが、ラジオボタンでユーザーを選択するとユーザー登録用のフォームが2つ出てきて、ラジオボタンでチームを選択するとチーム登録用のフォームが2つ出るようにしたいです。
6
+
7
+
5
8
  ### 発生している問題・エラーメッセージ
6
9
  ラジオボタンでユーザーを選択した場合の表示は正常なのですが、ラジオボタンでチームを選択した場合にフォームが切り替わることなくフォームが増えてしまう現象が起きる。(消えてほしいものが消えない)
7
10
 

1

言語名を変更

2018/08/28 15:13

投稿

moppu
moppu

スコア9

title CHANGED
File without changes
body CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ### 該当のソースコード
11
11
 
12
- ```js
12
+ ```html
13
13
  <form class="form-control" action="./score" method="post">
14
14
  <table class="layout-set" border="0" cellspacing="0" cellpadding="0">
15
15
  <tr>