使用html和JavaScript中的表单创建测验

时间:2016-11-07 17:24:51

标签: php javascript html forms

我有一个表格,就是这样:

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(@"C:\zzx\Project\SM\R5.1\Harness\InBound.xml");
        XmlNode sigNode = xmlDoc.SelectSingleNode("/UpdateInboundim613Response/model/instance/OVSCTicketID");
        if (sigNode != null)
        {
            Console.WriteLine(sigNode.InnerText);
        }

我需要什么?你可以看到,有一个<!DOCTYPE HTML> <html> <head> <title></title> <meta charset="utf-8"> </head> <body> <form action="lab4.php" method="POST"> 1. That man does look rather strange but you shouldn’t ______ at him. <br> <select name="vop1" style="width: 100px;" required> <option value=""></option> <option value="v11">glare</option> <option value="v12">blink</option> <option value="v13">stare</option> <option value="v14">frown</option> </select> <p></p> 2. He made a hole in the fence so that he could ______ through without being seen. <br> <select name="vop2" style="width: 100px;" required> <option value=""></option> <option value="v21">peer</option> <option value="v22">blink</option> <option value="v23">wink</option> <option value="v24">peep</option> </select> <p></p> 3. If you go out into bright sunlight after being in the dark, you sometimes ______. <br> <select name="vop3" style="width: 100px;" required> <option value=""></option> <option value="v31">peer</option> <option value="v32">blink</option> <option value="v33">glare</option> <option value="v34">peep</option> </select> <p></p> <button type="submit" name="submit" >GO</button> <input type="reset" value="Reset"> </form> </body> </html> 。我用这个表格用php。在PHP中,我从所有3个问题中获取值并总结它们。像这样:<form action="lab4.php" method="POST">

最后我写了这样的话:if ($_POST[vop1] == v11){$sum++;}if ($sum == 3) echo "Very good, you have answered 3 questions!"

因此,使用此表单,我需要使用JavaScript执行相同的操作。什么是获取我的价值,总结它并用JavaScript编写它的代码,就像PHP已经做到的那样?

1 个答案:

答案 0 :(得分:2)

使用Javascript不是测验的理想选择,因为可以使用html页面的源代码攻击答案。

仅供您理解,

选项#1:

<script>
   var sum=0;
   function checkAns(){
   if(document.getElementByName('vop1').value=='v11') 
       sum++;
   ....
   ....
</script>

OR

选项#2:

<强> 的Javascript

<script>
var sum=0;
function checkq1(ans) { 
    if(ans=='v11')
        sum++;
}
</script>

<强> HTML:

1. That man does look rather strange but you shouldn’t ______ at him. <br>
<select name="vop1" style="width: 100px;" required onchange="checkq1(this.value)"> 
<option value=""></option>
<option value="v11">glare</option>
<option value="v12">blink</option>
<option value="v13">stare</option>
<option value="v14">frown</option>
</select>