테스트 사이트 - 개발 중인 베타 버전입니다

name을 어떻게 써야하나요? 채택완료

망이망소이 7년 전 조회 1,786

단순 합계 내는 소스입니다.

 

 

디비에 저장이 안되서요.

input name 명이 

buy1, buy2... 이런식으로 들어가줘야 할것 같은데 그렇게쓰면 

스크립트가 작동안하고...

 

스크립트나 input의 name을 어떻게 써줘야 할련지요?^^

 

</p>

<p><div class="tbl_frm018 tbl_wrap estimate1">

    <table>

        <tr>

            <th rowspan="4" scope="row"><label for="wr_5">견적<strong class="sound_only"></strong></label></th>

            <td></p>

<p>

<form name="form">

<?

$wr50 = explode("|",$write['wr_50']);

$buy1 = $wr50[0];

$buy2 = $wr50[1]; 

$buy3 = $wr50[2]; 

$buy4 = $wr50[3]; 

?>            

            <input name="chkbox" type="checkbox" value="10000000" onClick="itemSum(this.form);" <?php echo ($buy1 == "10000000") ? "selected" : "";?>> 일반형

            </td>

          </tr>

          <tr>

            <td height="25">

            <input name="chkbox" type="checkbox" value="20000000" onClick="itemSum(this.form);" <?php echo ($buy2 == "20000000") ? "selected" : "";?>> 고급형</td>

          </tr>

          <tr>

            <td height="25">

            <input name="chkbox" type="checkbox" value="30000000" onClick="itemSum(this.form);" <?php echo ($buy3 == "30000000") ? "selected" : "";?>> 프리미엄형</td>

          </tr>

          <tr>

            <td height="25"> 합계: <input name="total_sum" type="text" size="20" value="<?=$buy4?>" readonly> 원</td>

          </tr>

</form> 

 </p>

<p></table>

</div></p>

<p> </p>

<p> </p>

<p>//스크립트</p>

<p><script language="javascript">

function itemSum(frm)

{

   var sum = 0;

   var count = frm.chkbox.length;

   for(var i=0; i < count; i++ ){

       if( frm.chkbox[i].checked == true ){

        sum += parseInt(frm.chkbox[i].value);

       }

   }

   frm.total_sum.value = sum;

}

</script></p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
e
7년 전

form 을 전송해서 DB에 저장하신다면,

name 을 다르게 해야 그 변수 그대로 받아서 저장할수 있구요.

입력 화면의 계산은 id="" 를 설정하셔서 처리하세요.

소스까지 만들어 드려야 하나요??

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

망이망소이
7년 전
네 하나만 부탁드려요^

댓글을 작성하려면 로그인이 필요합니다.

참고하실분들 보시든지...

</p>

<p><div class="tbl_frm018 tbl_wrap estimate1">



<?

$wr50 = explode("|",$write['wr_50']);

$item1 = $wr50[0];

$item2 = $wr50[1]; 

$item3 = $wr50[2]; 

$total = $wr50[3]; 

?>            

    <table>

        <tr>

            <th rowspan="4" scope="row"><label for="wr_5">통 인테리어<strong class="sound_only"></strong></label></th>

            <td>

            <input type=checkbox name=item1 value='10000000' onClick="sum(this)" <? if ($item1 == '10000000') echo "checked";?>> 일반형

            </td>

          </tr>

          <tr>

            <td height="25">

            <input type=checkbox name=item2 value='20000000' onClick="sum(this)" <? if ($item2 == '20000000') echo "checked";?>> 고급형</td>

          </tr>

          <tr>

            <td height="25">

            <input type=checkbox name=item3 value='30000000' onClick="sum(this)" <? if ($item3 == '30000000') echo "checked";?>> 프리미엄형</td>

          </tr>

          <tr>

            <td height="25"> 합계: <input type=text name=total value="<?=$total?>" readonly> 원 (vat 포함가)</td>

          </tr>

</table></p>

<p><script>

function sum(obj) {

  var oColl = obj.form.elements;

  var total = 0;

  for (var i=0; i < oColl.length; i++) {

    if (oColl[i].name.substr(0,4)=="item" && oColl[i].checked)

      total += parseInt(oColl[i].value);

  }

  obj.form.total.value = total;

}

</script>



</div></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

https://sir.kr/bbs/profile.php?mb_id=eyekiss" onclick="return false;" rel="nofollow" target="_blank" title="eyekiss 자기소개">eyekiss 님 조언대로

id값으로 계산하니까 쉽게 해결되네요 감사합니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인