input 체크박스 더하기 문의드립니다! 채택완료

안녕하세요!

라디오의 값을 인풋1, 인풋2, 인풋3에 출력되게 하고 

여기서 그 숫자를 더한 결과값을 출력해 주려고 합니다.

http://utogether.cafe24.com/bbs/page.php?hid=p201

Copy
<script>
<!--
function checkfunction()
{
 with(document.all)
 {

  for(i=0; i<a.length; i++)
  {
   if(a[i].checked==true)
   {
    content1.value = a[i].value;
   }
  }


  for(i=0; i<b.length; i++)
  {
   if(b[i].checked==true)
   {
    content2.value = b[i].value;
   }
  }

  for(i=0; i<c.length; i++)
  {
   if(c[i].checked==true)
   {
    content3.value = c[i].value;
   }
  }


 }
}
//-->


<!--
function sum()
{
    var obj = document.sumfrm;
    var sum=0;
    for(i=0;i<obj.content.length;i++)
    {
        if(obj.content[i].value*0 == 0)
        {
            sum += obj.content[i].value*1;
        }
    }
    obj.sum_content.value = sum;
}
//-->

</script>

제가 개발자가 아니어서 잘 모르는 상태인데, 여기저기서 퍼와가지고 작업한거라 뭐가 뭔지도 모르겠습니다^^;;

Copy
<form name='sumfrm' method="post" action="">


<input type='radio' name='a' value='24200' onclick='javascript:checkfunction()'> 24200
<input type='radio' name='a' value='29700' onclick='javascript:checkfunction()'> 29700
<input type='radio' name='a' value='35200' onclick='javascript:checkfunction()'> 35200


<br><br>

<input type='radio' name='b' value='12100' onclick='javascript:checkfunction()'> 12100
<input type='radio' name='b' value='16500' onclick='javascript:checkfunction()'> 16500
<input type='radio' name='b' value='18700' onclick='javascript:checkfunction()'> 18700
<input type='radio' name='b' value='26300' onclick='javascript:checkfunction()'> 26300
<input type='radio' name='b' value='28800' onclick='javascript:checkfunction()'> 28800

<br><br>

<input type='radio' name='c' value='6600' onclick='javascript:checkfunction()'> 6600
<input type='radio' name='c' value='7700' onclick='javascript:checkfunction()'> 7700
<input type='radio' name='c' value='9900' onclick='javascript:checkfunction()'> 9900
<input type='radio' name='c' value='9900' onclick='javascript:checkfunction()'> 9900
<input type='radio' name='c' value='11000' onclick='javascript:checkfunction()'> 11000

<br><br>

<input type="text" name="content" id='content1' onBlur="sum()" value="0">
<input type="text" name="content" id='content2' onBlur="sum()" value="0">
<input type="text" name="content" id='content3' onBlur="sum()" value="0">
결과 : <input type="text" name="sum_content">

이게 계산은 잘 되는데 꼭 인풋1이나 결과부분을 눌러줘야만 결과값이 나오더라고여;;

혹시 해결책이 있거나 힌트가 있다면...

알려주시면 감사하겠습니다!

답변 3개

채택된 답변
+20 포인트

function checkfunction() 에 sum(); 을 추가해주면 됩니다.

function checkfunction() {

 ~

 sum();

}

Copy
<script>
function checkfunction()
{
 with(document.all)
 {
  for(i=0; i<a.length; i++)
  {
   if(a[i].checked==true)
   {
    content1.value = a[i].value;
   }
  }

  for(i=0; i<b.length; i++)
  {
   if(b[i].checked==true)
   {
    content2.value = b[i].value;
   }
  }
  for(i=0; i<c.length; i++)
  {
   if(c[i].checked==true)
   {
    content3.value = c[i].value;
   }
  }

 }

 

 sum();


}
//-->

<!--
function sum()
{
    var obj = document.sumfrm;
    var sum=0;
    for(i=0;i<obj.content.length;i++)
    {
        if(obj.content[i].value*0 == 0)
        {
            sum += obj.content[i].value*1;
        }
    }
    obj.sum_content.value = sum;
}
</script>
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

감사합니다!!!!

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

Copy
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
1 <input type="radio" name="num1" value="1" id="num1" class="sum"/>
2 <input type="radio" name="num1" value="2" id="num1" class="sum"/> <br />

3 <input type="radio" name="num2" value="3" id="num2" class="sum"/>
4 <input type="radio" name="num2" value="4" id="num2" class="sum"/> <br />

5 <input type="radio" name="num3" value="5" id="num3" class="sum"/>
6 <input type="radio" name="num3" value="6" id="num3" class="sum" /> <br />

7 <input type="radio" name="num4" value="7" id="num4" class="sum"/>
8 <input type="radio" name="num4" value="8" id="num4" class="sum"/> <br />

Total: <input type="text" name="total" id="total"/>

<script>
    $(".sum").click(function() {
      var total = 0;
      $(".radi:checked").each(function() { total += +this.value; });
      $("#total").val(total);
    });
</script>
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

잘 해결했습니다! 감사합니다^^

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

checkfunction() 함수 마지막에
sum() 함수를 호출해보세요

function checkfunction()
{
 with(document.all)
 {
     // .... 생략
    sum();
 }
}

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

답변에 대한 댓글 1개

감사합니다!!

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

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

로그인
🐛 버그신고