这是我的代码。我正在准备离线测验系统。此代码显示有选项字段的多个问题。现在在无线电变量中,目前它存储由用户提交的问题选项,其名称为q1。由于每个问题集的名称都是动态的,如何在无线电变量中存储多个值?
喜欢q1,q2等选项......等等......
<script type="text/javascript">
var currentPath = ((location+"").replace(/%20/g, " ").replace("file:///", "").replace("/", "\\").replace("index.html", ""));
var pad = currentPath+"\\quiz.mdb";
//var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pad;
var strConn = "Provider=microsoft.ace.oledb.12.0;Data Source=" + pad;
var cn = new ActiveXObject("ADODB.Connection");
cn.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "SELECT * FROM ques_bank WHERE quizno = 'q_001'";
rs.Open(SQL, cn);
var sList = "<form target='sendinfo' id='infoform' onSubmit='return handleClick()'>";
while (!rs.EOF) {
sList = sList +
"<p>"+rs("question")+ "</p><br>"+
"<input type='radio' name='q"+ rs("ID") +"' value='a' />"+rs("optionA")+"<br>"+
"<input type='radio' name='q"+ rs("ID") +"' value='b' />"+rs("optionB")+"<br>"+
"<input type='radio' name='q"+ rs("ID") +"' value='c' />"+rs("optionC")+"<br>"+
"<input type='radio' name='q"+ rs("ID") +"' value='d' />"+rs("optionD")+"<br>"+
"<input type='radio' name='q"+ rs("ID") +"' value='e' />"+rs("optionE")+"<br>"+
"<input type='text' id='rank_list' name='q_id' value='"+ rs("ID") +"' /><br>"+
"<hr>";
rs.MoveNext();
}
document.write(sList+"<input type='submit' value='Submit'/></form>");
function test() {
}
//submit function
function handleClick() {
var radios = document.getElementsByName("q1");
var found = 1;
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
alert(radios[i].value);
found = 0;
break;
}
}
if(found == 1) {
alert("Please Select Radio");
}
//event.preventDefault(); // disable normal form submit behavior
return false; // prevent further bubbling of event
}
rs.Close();
cn.Close();
</script>