혹시 이놈을 자동합계하려면 스크립트를 어찌 써야 할까요 ? 채택완료
a233454
8년 전
조회 4,549
</p><p> <tr></p><p> <th scope="row"><label for="wr8">상품명</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[0]; ?>" class="frm_input" size="50"></td></p><p> <th scope="row"><label for="wr8">수량</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[1]; ?>" class="frm_input"></td></p><p> <th scope="row"><label for="wr8">개당가격</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[2]; ?>" class="frm_input"></td></p><p> </tr></p><p>
</p><p> <tr></p><p> <th scope="row"><label for="wr8">상품명</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[3]; ?>" class="frm_input" size="50"></td></p><p> <th scope="row"><label for="wr8">수량</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[4]; ?>" class="frm_input"></td></p><p> <th scope="row"><label for="wr8">개당가격</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[5]; ?>" class="frm_input"></td></p><p> </tr></p><p>
</p><p>
</p><p> <tr></p><p> <th scope="row"><label for="wr8">상품명</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[6]; ?>" class="frm_input" size="50"></td></p><p> <th scope="row"><label for="wr8">수량</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[7]; ?>" class="frm_input"></td></p><p> <th scope="row"><label for="wr8">개당가격</label></th></p><p> <td><input type="text" name="wr8[]" value="<?php echo $wr8[8]; ?>" class="frm_input"></td></p><p> </tr></p><div>
프로그램에 무뇌인이 회사에서 조금 소스 수정만 할 줄 아는데 이것좀 도와주세요..
스크립트 소스좀 도와주세요..ㅠㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변 4개
채택된 답변
+20 포인트
8년 전
아래처럼 가능은 합니다.
하지만 중요한 것은 서버측 검증처리 이고
서버측 검증처리가 필요하다고 하면
클라이언트로 꾸민 효과의 결과와 서버로 넘어간 결과의 데이터는
일치해야 하는게 중요한 것이구요.
현재 소스는 name 이 모두 동일 하므로
서버측 검증이 애매할 가능성이 큽니다.
참고 용으로 이런 방법으로 가능하다 정도만 가늠하시기 바랍니다.
</p><p><!DOCTYPE html></p><p><html></p><p> <head></p><p> <meta charset="UTF-8" /></p><p> <title>title</title></p><p>
</p><p> <script type="text/javascript" src="<a href="<a href="http://code.jquery.com/jquery.min.js" target="_blank" rel="noopener noreferrer">http://code.jquery.com/jquery.min.js</a>"><a href="http://code.jquery.com/jquery.min.js" target="_blank" rel="noopener noreferrer">http://code.jquery.com/jquery.min.js</a></a>"></script></p><p> <script type="text/javascript"></p><p> function test(objid) {</p><p> var rtn = 0;</p><p> var tmp = 0;</p><p> $("#" + objid + ' input[type="text"]').each(function (index) {</p><p> switch (index % 3) {</p><p> case 0: // 상품명</p><p> tmp = 0;</p><p> break;</p><p> case 1: // 수량</p><p> tmp += Number($(this).val());</p><p> break;</p><p> case 2: // 개당가격</p><p> rtn += tmp * Number($(this).val());</p><p> break;</p><p> }</p><p> });</p><p> $("#prices_all").html(rtn);</p><p> }</p><p> </script></p><p> </p><p> </head></p><p> <body></p><p>
</p><p> <table id="prices"></p><p> <tr></p><p> <th scope="row"><label for="wr8">상품명</label></th></p><p> <td><input type="text" name="wr8[]" value="aaa" class="frm_input" size="50"></td></p><p> <th scope="row"><label for="wr8">수량</label></th></p><p> <td><input type="text" name="wr8[]" value="1" class="frm_input"></td></p><p> <th scope="row"><label for="wr8">개당가격</label></th></p><p> <td><input type="text" name="wr8[]" value="10" class="frm_input"></td></p><p> </tr></p><p>
</p><p> <tr></p><p> <th scope="row"><label for="wr8">상품명</label></th></p><p> <td><input type="text" name="wr8[]" value="bbb" class="frm_input" size="50"></td></p><p> <th scope="row"><label for="wr8">수량</label></th></p><p> <td><input type="text" name="wr8[]" value="3" class="frm_input"></td></p><p> <th scope="row"><label for="wr8">개당가격</label></th></p><p> <td><input type="text" name="wr8[]" value="20" class="frm_input"></td></p><p> </tr></p><p>
</p><p>
</p><p> <tr></p><p> <th scope="row"><label for="wr8">상품명</label></th></p><p> <td><input type="text" name="wr8[]" value="ccc" class="frm_input" size="50"></td></p><p> <th scope="row"><label for="wr8">수량</label></th></p><p> <td><input type="text" name="wr8[]" value="6" class="frm_input"></td></p><p> <th scope="row"><label for="wr8">개당가격</label></th></p><p> <td><input type="text" name="wr8[]" value="30" class="frm_input"></td></p><p> </tr></p><p> </table></p><p>
</p><p> <input type="button" onclick="test('prices')" value="합계" /></p><p> : <span id="prices_all"></span></p><p>
</p><p> </body></p><p></html></p><p>
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
8년 전
</p><p><script type="text/javascript">
$(function() {
$("#cal").on("click", function() {
var ea = price = total = 0;
$("table tr").each(function() {
ea = $(this).find("input[name='wr8[]']:eq(1)").val();
price = $(this).find("input[name='wr8[]']:eq(2)").val();
total += ea * price;
});
$("#result").text(total);
});
});
</script></p><p>
http://nyaongii.dothome.co.kr/temp/wrid_205082.html">http://nyaongii.dothome.co.kr/temp/wrid_205082.html
억지로 맞춰서 하면 이런 식으로도 가능하긴 합니다.
근데 어지간하면 개수, 가격 이런 건 다른 name을 쓰시는 게 좋습니다.
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
a
a233454
8년 전
어려운 작업이네요..
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인