我想做一个简单的测试,通过单选按钮提问和回答标记,但我被卡住了。
我有 6 个单独的测试,全部由 10 个问题组成,您将在代码中看到。我用10个问题做了两个测试,我的问题是让他们自己个性化,这样我就能得到不同的答案。
我想要的是当有人标记“是”然后他/她在测试结束时得到肯定答案或“是”答案的总和。
这是代码:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function DisplayPrice(price){
var val1 = 0;
for( i = 0; i < document.form1.price.length; i++ ){
if( document.form1.price[i].checked == true ){
val1 = document.form1.price[i].value;
}
}
var val2 = 0;
for( i = 0; i < document.form2.price2.length; i++ ){
if( document.form2.price2[i].checked == true ){
val2 = document.form2.price2[i].value;
}
}
var val3 = 0;
for( i = 0; i < document.form3.price3.length; i++ ){
if( document.form3.price3[i].checked == true ){
val3 = document.form3.price3[i].value;
}
}
var val4 = 0;
for( i = 0; i < document.form4.price4.length; i++ ){
if( document.form4.price4[i].checked == true ){
val4 = document.form4.price4[i].value;
}
}
var val5 = 0;
for( i = 0; i < document.form5.price5.length; i++ ){
if( document.form5.price5[i].checked == true ){
val5 = document.form5.price5[i].value;
}
}
var val6 = 0;
for( i = 0; i < document.form6.price6.length; i++ ){
if( document.form6.price6[i].checked == true ){
val6 = document.form6.price6[i].value;
}
}
var val7 = 0;
for( i = 0; i < document.form7.price7.length; i++ ){
if( document.form7.price7[i].checked == true ){
val7 = document.form7.price7[i].value;
}
}
var val8 = 0;
for( i = 0; i < document.form8.price8.length; i++ ){
if( document.form8.price8[i].checked == true ){
val8 = document.form8.price8[i].value;
}
}
var val9 = 0;
for( i = 0; i < document.form9.price9.length; i++ ){
if( document.form9.price9[i].checked == true ){
val9 = document.form9.price9[i].value;
}
}
var val10 = 0;
for( i = 0; i < document.form10.price10.length; i++ ){
if( document.form10.price10[i].checked == true ){
val10 = document.form10.price10[i].value;
}
}
var sum=parseInt(val1) + parseInt(val2) + parseInt(val3) + parseInt(val4) + parseInt(val5) + parseInt(val6) + parseInt(val7) + parseInt(val8) + parseInt(val9) + parseInt(val10);
document.getElementById('totalSum').value=sum;
}
</script>
<style type="text/css">
body,td,th {
color: #03C;
}
body {
background-color: #999;
text-align: left;
}
</style>
</head>
<body>
<h2><strong>TEST 1</strong></h2>
<form name="form1" id="form1" runat="server">
<h3><br>
QUESTION1.
<input id="rdo_1" type="radio" value="1" name="price" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form2" id="form2" runat="server">
<h3><br>
QUESTION2.
<input id="rdo_1" type="radio" value="1" name="price2" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price2" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form3" id="form3" runat="server">
<h3><br>
QUESTION3.
<input id="rdo_1" type="radio" value="1" name="price3" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price3" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form4" id="form4" runat="server">
<h3><br>
QUESTION4.
<input id="rdo_1" type="radio" value="1" name="price4" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price4" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form5" id="form5" runat="server">
<h3><br>
QUESTION5.
<input id="rdo_1" type="radio" value="1" name="price5" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price5" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form6" id="form6" runat="server">
<h3><br>
QUESTION6.
<input id="rdo_1" type="radio" value="1" name="price6" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price6" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form7" id="form7" runat="server">
<h3>QUESTION7.
<input id="rdo_1" type="radio" value="1" name="price7" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price7" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form8" id="form8" runat="server">
<h3><br>
QUESTION8.
<input id="rdo_1" type="radio" value="1" name="price8" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price8" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form9" id="form9" runat="server">
<h3><br>
QUESTION9.
<input id="rdo_1" type="radio" value="1" name="price9" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price9" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form10" id="form10" runat="server">
<h3>QUESTION10.
<input id="rdo_1" type="radio" value="1" name="price10" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_2" type="radio" value="0" name="price10" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<p> </p>
<h2><strong>TEST 2</strong></h2>
<form name="form1" id="form11" runat="server">
<h3><br>
QUESTION1.
<input id="rdo_3" type="radio" value="1" name="price" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form2" id="form12" runat="server">
<h3><br>
QUESTION2.
<input id="rdo_3" type="radio" value="1" name="price2" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price2" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form3" id="form13" runat="server">
<h3><br>
QUESTION3.
<input id="rdo_3" type="radio" value="1" name="price3" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price3" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form4" id="form14" runat="server">
<h3><br>
QUESTION4.
<input id="rdo_3" type="radio" value="1" name="price4" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price4" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form5" id="form15" runat="server">
<h3><br>
QUESTION5.
<input id="rdo_3" type="radio" value="1" name="price5" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price5" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form6" id="form16" runat="server">
<h3><br>
QUESTION6.
<input id="rdo_3" type="radio" value="1" name="price6" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price6" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form7" id="form17" runat="server">
<h3>QUESTION7.
<input id="rdo_3" type="radio" value="1" name="price7" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price7" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form8" id="form18" runat="server">
<h3><br>
QUESTION8.
<input id="rdo_3" type="radio" value="1" name="price8" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price8" onClick="DisplayPrice(this.value);">
NO<br>
</h3>
</form>
<form name="form9" id="form19" runat="server">
<h3><br>
QUESTION9.
<input id="rdo_3" type="radio" value="1" name="price9" onClick="DisplayPrice(this.value);">
YES
<input id="rdo_4" type="radio" value="0" name="price9" onClick="DisplayPrice(this.value);">
NO <br>
</h3>
</form>
<form name="form10" id="form20" runat="server">
<h3><br>
QUESTION10.
<input id="rdo_3" type="radio" value="1" name="price10" onClick="DisplayPrice(this.value);">
DA
<input id="rdo_4" type="radio" value="0" name="price10" onClick="DisplayPrice(this.value);">
NE<br>
</h3>
</form>
<h2>Score "TEST1"
<input type="text" name="totalSum" id="totalSum" value="" size="3" readonly="readonly">
</h2>
<h2>Score "TEST2"
<input type="text" name="totalSum2" id="totalSum2" value="" size="3" readonly="readonly">
</h2>
</body>