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

질문의 총합계를 구하고 싶은데 계속 개당 질문에 답변이 구해집니다 채택완료

가가양 10년 전 조회 2,556

안녕하세요 라디오 버튼 합계를 구하는건데  0 , 1,  2,  3,  4 중에 한가지만 선택했을때의 합계를 구하고 싶습니다 지금 되어있는건 질문1의 4를 선택했을때와 다시 3을 선택했을때 합이 구해져서요 질문에 대한 답변을 선택하였을때 총합계를 구하고 싶어요 질문1 답변의 01234 중 한개의 값 질문2 답변의 01234 중 한개의 값 질문3 답변의 01234 중 한개의 값 ​ .... 총 질문에 대한 답변의 값 도와주세요

 

 

 

 

http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document title>
 
 head>
 
 <body>
<script type="text/javascript">
script>
 
<div>질문에 대한 합계를 구합니다 ;;div>
<form method="post" name="questionform" >
<p>질문1.p>
<input type="radio" name="question1" value="0" onclick="this.form.total.value=select_item(this);" />1) ㄱㄱㄱ
<input type="radio" name="question1" value="1" onclick="this.form.total.value=select_item(this);" />2) ㄴㄴㄴ
<input type="radio" name="question1" value="2" onclick="this.form.total.value=select_item(this);" />3) ㄷㄷㄷ
<input type="radio" name="question1" value="3" onclick="this.form.total.value=select_item(this);" />4) ㄹㄹㄹ
<input type="radio" name="question1" value="4" onclick="this.form.total.value=select_item(this);" />5) ㅁㅁㅁ
  
<p>질문2.p>
<input type="radio" name="question2" value="0" onclick="this.form.total.value=select_item(this);" />1) ㄱㄱㄱ
<input type="radio" name="question2" value="1" onclick="this.form.total.value=select_item(this);" />2) ㄴㄴㄴ
<input type="radio" name="question2" value="2" onclick="this.form.total.value=select_item(this);" />3) ㄷㄷㄷ
<input type="radio" name="question2" value="3" onclick="this.form.total.value=select_item(this);" />4) ㄹㄹㄹ
<input type="radio" name="question2" value="4" onclick="this.form.total.value=select_item(this);" />5) ㅁㅁㅁ
 
 
<div>
  <input type="hidden" name="hidd_total" value="0" />
  <input type="hidden" name="hidd_radio" value="0" />
  <input type="text" name="total" id="total" value="" readonly style="text-align:center;background-color:red"/>
div>
form>
  
 body>
html>

 

 

 

 

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

답변 2개

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

</p><p><meta charset="utf-8" />
</script>
<input type="radio" name="question1" value="0" onclick="_total()" />1) ㄱㄱㄱ 
<input type="radio" name="question1" value="1" onclick="_total()" />2) ㄴㄴㄴ
<input type="radio" name="question1" value="2" onclick="_total()" />3) ㄷㄷㄷ
<input type="radio" name="question1" value="3" onclick="_total()" />4) ㄹㄹㄹ
<input type="radio" name="question1" value="4" onclick="_total()" />5) ㅁㅁㅁ
  </p><p><p>질문2.</p>
<input type="radio" name="question2" value="0" onclick="_total()" />1) ㄱㄱㄱ
<input type="radio" name="question2" value="1" onclick="_total()" />2) ㄴㄴㄴ
<input type="radio" name="question2" value="2" onclick="_total()" />3) ㄷㄷㄷ
<input type="radio" name="question2" value="3" onclick="_total()" />4) ㄹㄹㄹ
<input type="radio" name="question2" value="4" onclick="_total()" />5) ㅁㅁㅁ</p><p><input type="text" name="total" id="total" value="" readonly style="text-align:center;background-color:red"/>
<script type="text/javascript">
function _total() {
   var radio = document.querySelectorAll("input:checked");
   var total = i = 0;
   for(i=0; i<radio.length; i++) total += radio[i].value * 1;
      document.getElementById("total").value = total;
}
</script>​</p><p>

 

참고로 querySelectorAll() 메소드는 ie 같은 경우 9 이상에서만 작동합니다.

그리고 jquery 사용하시는 게 훨씬 편하실 텐데... 

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

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

10년 전

정말 감사합니다.

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

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

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

로그인

© 2025 SIRSOFT. All rights reserved.