如何在表单中提交多个组合框并使用javascript(测验应用程序)进行检查

How to submit multiple combobox in a form and check using javascript(Quiz application)?

本文关键字:javascript 进行检查 应用程序 表单 提交 组合      更新时间:2023-09-26

我尝试进行测验/考试申请。我对创建单选题没有问题(我的参考来自 http://www.javascriptkit.com/script/cut180.shtml),但我仍然困惑如何制作多项选择题。对于单一选择,我可以简单地使用单选按钮:

  <form method="POST" name="myquiz">
  <div class="qheader">
  9) What's the world's most widely spoken language?</div>
  <div class="qselections">
  <input type="radio" value="a" name="question9">a) English<br>
  <input type="radio" value="b" name="question9">b) Spanish<br>
  <input type="radio" value="c" name="question9">c) Mandarin<br>
  <input type="radio" value="d" name="question9">d) French<br>
  </div>
  </form>

对于评分,他们使用javascript:

//Enter total number of questions:
var totalquestions=10
//Enter the solutions corresponding to each question:
var correctchoices=new Array()
correctchoices[1]='a' //question 1 solution
correctchoices[2]='a' //question 2 solution, and so on.
correctchoices[3]='c'
correctchoices[4]='c'
correctchoices[5]='c'
correctchoices[6]='c'
correctchoices[7]='b'
correctchoices[8]='b'
correctchoices[9]='c'
correctchoices[10]='b'
/////Don't edit beyond here//////////////////////////
function gradeit(){
var incorrect=null
for (q=1;q<=totalquestions;q++){
    var thequestion=eval("document.myquiz.question"+q)
    for (c=0;c<thequestion.length;c++){
        if (thequestion[c].checked==true)
        actualchoices[q]=thequestion[c].value
        }

等。。。

问题是当我尝试制作多项选择题时,我尝试使用这个,但仍然失败:

<div class="qheader">
1) What is the difference between a jungle and a rain forest?</div>
<div class="qselections">
<input type="checkbox" value="a" name="question1">a) No difference. Simply two different ways in referring to the same thing.<br>
<input type="checkbox" value="b" name="question1">b) A jungle in general receives less rain than a rain forest.<br>
<input type="checkbox" value="c" name="question1">c) A jungle refers to the thickest area of a rain forest<br>
<input type="checkbox" value="d" name="question1">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>
</div>

<div class="qheader">
    1) What is the difference between a jungle and a rain forest?</div>
    <div class="qselections">
    <input type="checkbox" value="a" name="question1[]">a) No difference. Simply two different ways in referring to the same thing.<br>
    <input type="checkbox" value="b" name="question1[]">b) A jungle in general receives less rain than a rain forest.<br>
    <input type="checkbox" value="c" name="question1[]">c) A jungle refers to the thickest area of a rain forest<br>
    <input type="checkbox" value="d" name="question1[]">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>
    </div>
你应该

question1,question2,question3,....一样使用checkboxes names

<input type="checkbox" value="a" name="question1">a) No difference. Simply two different ways in referring to the same thing.<br>
<input type="checkbox" value="b" name="question2">b) A jungle in general receives less rain than a rain forest.<br>
<input type="checkbox" value="c" name="question3">c) A jungle refers to the thickest area of a rain forest<br>
<input type="checkbox" value="d" name="question4">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>