0

这是我的代码。我正在准备一个离线测验系统。此代码显示带有选项字段的多个问题。现在在单选变量中,目前它存储了用户名为 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>
4

0 回答 0