こんにちは。
JavaScriptを使用して開発を行っている者です。
タイトルの通りなのですが、ModalWindowに変数の値を表示させたいのですがうまくいかないため
質問させていただきました。
やり方として考えているのが、<Script>内でのAllowanceCopy()に表示させたい変数の値を
渡して、その中でModalWindowのコンテンツとなる部分のテーブル、<tr>を取得して、その中の
空の<td>に値を設定するという事を考えていました。
それでとりあえず記述してみたのが以下のコードです。
引数にしたい変数は、String compenName・String workerName・int totalです。
引数の記述の仕方やJavaScriptの記述の仕方の間違いのご指摘や、
変数を表示させるやり方自体についてアドバイスをいただきたいと思っております。
お手数ですがよろしくお願いいたします。
Java
1<table class="table" rules="all"> 2 <tr> 3 <td class="td">職人名</td> 4 <% 5 int count = 0; 6 int[] sum = new int[compenList.size()]; 7 8 //取得した手当の全種類を表示する 9 10 if (compenList != null ) { 11 for(int i = 0; i < compenList.size(); i++) { 12 13 Compensation c = compenList.get(i); 14 compenName = compenList.get(i).getName(); 15 %> 16 <td class="td" 17 <%= c.getId() < 0 ? "" : "onclick=\"UpdateCompensation('" + c.getName() + "', " + c.getId() + ", '" + c.getUnit() + "', " + c.getUnitprice() + ")\"" %>> 18 19 <%= compenName%> 20 21 </td> 22 23 <% 24 } 25 } 26 %> 27 </tr> 28 29 <% 30 ArrayList<Worker>worker = null; 31 32 //全職人の情報を取得 33 if (groupList != null ) { 34 for(int i = 0; i < groupList.size(); i++) { 35 Group group = groupList.get(i); 36 worker = group.getAllMember(); 37 %> 38 <% 39 40 //全職人のフルネームを取得 41 for (int j = 0; j < worker.size();j++) { 42 workerName = worker.get(j).getFullname(); 43 %> 44 45 <tr> 46 <td align="center"> 47 <%= workerName%> 48 </td> 49 50 <% 51 //allowanceListとGroupLIst/memberの順番は対応している 52 for (int i2 = 0;i2 < compenList.size(); i2++ ) { 53 total = 0; 54 float floatTotal = 0; 55 56 int compenID = compenList.get(i2).getId(); 57 58 //職人が持つ手当のリスト 59 ArrayList<Allowance>allowanceInfo = allowanceList.get(count); 60 Allowance allowance = null; 61 62 for (int j2 = 0;j2 < allowanceInfo.size();j2++) { 63 allowance = allowanceInfo.get(j2); 64 65 if (allowance.getCompensation().getId() == compenID) { 66 floatTotal = allowance.getUnitprice() * allowance.getQuantity(); 67 total += (int)Math.floor(floatTotal); 68 69 } 70 %> 71 <% 72 } 73 %> 74 <td align="center" onclick="AllowanceCopy(workerName,compenName,total)"><%= total%></td> 75 <% 76 sum[i2] += total; 77 } 78 count++; 79 } 80 } 81 } 82 83 %> 84 </tr> 85 <tr> 86 <td class="td">合計額</td> 87 <%for (int index= 0;index < sum.length;index++) { 88 %> 89 <td align="center"><%= sum[index]%>円</td> 90 <% 91 } 92 %> 93 </tr> 94 </table> 95 <%} %> 96 </form> 97 98 <!-- コピーしたい手当の期間を設定するwindow --> 99 100 <form action="<%= request.getContextPath()%>/allowanceCopy"> 101 <div id="modal_allowanceCopy" align="center"class="modal_window"> 102 <table id="allowance_copy" align="center"> 103 <tr> 104 <th><%=pageCompen %>の適用期間設定</th> 105 </tr> 106 <tr> 107 <td></td> 108 <td></td> 109 <td></td> 110 </tr> 111 <tr> 112 <td> 113 <input type="number" name="start_year" min="1950" max="2100" value="<%= _PAGE_YEAR_ %>"> 年 114 <input type="hidden" name="type" value="<%= compenType%>"> 115 <select name="start_month"> 116 <% for(int i = 0; i < 12; i++){ %> 117 <option value="<%= i + 1 %>"><%=i + 1 %></option> 118 <% } %> 119 </select> 月 120 ~ 121 <input type="number" name="end_year" min="1950" max="2100" value="<%= _PAGE_YEAR_ %>"> 年 122 <select name="end_month"> 123 <% for(int i = 0; i < 12; i++){ %> 124 <option value="<%=i + 1 %>"><%=i + 1 %></option> 125 <% } %> 126 </select> 月 127 </td> 128 </tr> 129 <tr> 130 <td align="right">まで適用する。</td> 131 </tr> 132 <tr> 133 <td align="center"> 134 <input type="submit" name="submit" value="決定"> 135 <input type="button" value="キャンセル"onclick="closeWindow()"> 136 </td> 137 </tr> 138 </table> 139 </div> 140 </form> 141 </div> 142 </body> 143</html> 144 145<script type="text/javascript" src="/yngd/view/js/common/modalWindow.js"></script> 146<script type="text/javascript" src="/yngd/view/js/common/utils.js"></script> 147<script type="text/javascript" src="/yngd/view/js/common/formCheck.js"></script> 148 149 150<script type="text/javascript"> 151 152MWOnloadFunction(); 153 154function UpdateCompensation(name,id,unit,unitprice) { 155 //windowを開く 156 modalOpen("modal_allowanceCreate"); 157 158 //選択された手当の情報を取得する(引数できてる)取得した情報を転記する 159 document.update.compenName.value = name; 160 console.log(document.update.compenName); 161 162 document.update.compenId.value = id; 163 console.log(document.update.compenId); 164 165 document.update.unit.value = unit; 166 console.log(document.update.unit); 167 168 document.update.unitPrice.value = unitprice; 169 console.log(document.update.unitPrice); 170 171 //入力チェック 172 FCOnloadFunction(document.update); 173} 174 175function AllowanceCopy(workerName,compenName,total) { 176 177 console.log(workerName); 178 console.log(compenName); 179 console.log(total); 180 181 var allowanceCopyTable = document.getElementById('allowance_copy'); 182 var tr = allowanceCopyTable.rows[1]; 183 184 for (var td = 0; td < tr.cells.length; td++) { 185 td = tr.cells[td]; 186 187 188 if (td == 0) { 189 td.firstChild.nodeValue = workerName; 190 191 192 } else if (td == 1) { 193 td.firstChild.nodeValue = compenName; 194 195 196 } else if (td == 2) { 197 td.firstChild.nodeValue = total; 198 199 } 200 201 } 202 203 //windowを開く 204 modalOpen("modal_allowanceCopy"); 205 206}
あなたの回答
tips
プレビュー