Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript向测验结果添加详细的输入表单_Javascript_Php_Html - Fatal编程技术网

使用Javascript向测验结果添加详细的输入表单

使用Javascript向测验结果添加详细的输入表单,javascript,php,html,Javascript,Php,Html,我目前正在准备一个在线测验。目前的代码运行良好,但我想看看谁的分数是多少。我对Javascript还是非常陌生,我一直在为一位朋友制作这个测试。我已经学到了很多,只是让这件事的工作 有人能告诉我如何添加一个或两个简单的文本输入,当在问题数组的末尾调用结果页面时会显示出来吗 我希望能够让用户输入他们的名字,并提交与结果一起使用php邮件 我试图在html区域中添加一个简单的html输入字段,如下所示,但它从未产生任何结果 <input name="Name" type="text" val

我目前正在准备一个在线测验。目前的代码运行良好,但我想看看谁的分数是多少。我对Javascript还是非常陌生,我一直在为一位朋友制作这个测试。我已经学到了很多,只是让这件事的工作

有人能告诉我如何添加一个或两个简单的文本输入,当在问题数组的末尾调用结果页面时会显示出来吗

我希望能够让用户输入他们的名字,并提交与结果一起使用php邮件

我试图在html区域中添加一个简单的html输入字段,如下所示,但它从未产生任何结果

 <input name="Name" type="text" value="" size="80">

var-allQuestions=[{
问题:“愤怒可以被认为是一种类似于其他感觉和情绪的情绪。”,
选择:[“情感”、“波长”、“连续性”、“锻炼”],
正确答案:2
}, {
问题:“当事情最终压倒他时,他通常会表现出坚强、沉默的性格。”,
选择:[“爆炸”、“内爆”、“离开”、“哭泣”],
正确答案:0
}, {
问题:“那些抱怨一切,认为自己是受害者的人,符合所谓的人格类型。”,
选择:[“检察官”、“牢骚满腹”、“灭绝者”、“终结者”],
正确答案:1
}, {
问题:“当有人想指出别人的缺点,以转移对自己的指责时,他可能是一个,
选择:[“置换者”、“恐吓者”、“检察官”、“抱怨者”],
正确答案:2
},
{
问题:“这种性格会把他的愤怒发泄在他认为比他真正生气的人“威胁更小”的人或事上。”,
选择:[“牢骚满腹”、“置换者”、“检察官”、“懦夫”],
正确答案:1
},
{
问题:“最容易发现的愤怒性格类型通常是愤怒。这些类型通常来自虐待背景。”,
选择:[“恐吓者”、“抱怨者”、“置换者”、“检察官”],
正确答案:0
},
{
问题:“愤怒有一个医学定义,说它是一种从愤怒到极度愤怒的状态。”,
选择:[“精神状态尴尬”、“情绪状态轻微刺激”、“疲惫状态打哈欠”、“典型状态放松”],
正确答案:1
},                    
{
问题:“愤怒经常被比作愤怒”,
选择:[“鹅群”、“木弦”、“压力锅”、“冰袋”],
正确答案:2
}, 
{
问题:“愤怒和愤怒可以成为一种暴力。这些人被称为拉格霍利克主义者。”,
选择:[“上瘾”、“皮肤病”、“问题”、“舒适区”],
正确答案:0
},                     
{
问题:“第一条规则是当你在家时什么都不要说!”,
选择:[“对”、“错”、“生气”、“困惑”],
正确答案:2
},                    
{
问题:“很多时候,我们感到愤怒,因为一种情况似乎是消极的,似乎与我们的目标相冲突。”,
选择:[“信仰体系”、“当前计划”、“家庭成员”、“时间表”],
正确答案:0
},                    
{
问题:“许多人都有信仰,这让他们一直感觉自己是受害者。”,
选择:[“斯多葛派”、“不同寻常的”、“非理性的”、“西方的”],
正确答案:2
}, 
{
问题:“要控制愤怒,我们所要做的就是学会从一个角度看待生活。”,
选项:[“个人”、“不同”、“封闭”、“未知”],
正确答案:1
},                     
];
//您可以通过数组访问复选框名称
//将数组编号与allQuestions数组中的编号匹配
var-questionNum=0;
var scoreNum=0;
var=”;
var failedQuestions=[];
$(文档).ready(函数(){
makeQuestions=函数(){
if(questionNum==allQuestions.length){
$(“输入[value=SUBMIT]”。删除();
$(“#问题”).text(“全部完成!”).append(
请单击下面的按钮提交结果。).append(
您的分数为“+”+scoreNum); $(“#问题”)。追加(“


”); $(“答案正确”).val(scoreNum); $(“#问题”).append(“失败的问题:+failedQuestions.join()); }否则{ $(“#问题”).text(所有问题[questionNum].question); for(var i=0;i$(“#words”).append(“+allQuestions[questionNum][choices'][i]+”我不确定这是否是您需要的,但我添加了一个提琴:


我添加了一个
div
,带有
id='name'
。其中包含一个
输入
字段,用于输入文本。当所有答案都提交后,将显示该字段。

将所有答案都放在客户端可能不明智。只需说声“谢谢您的输入,我的想法是在它工作后缩小并混淆。”正确。你有其他建议或是关于实际主题的建议吗?哇,谢谢,我把它放在你下面5行,脚本中没有任何变化。一定很晚了,但谢谢你让我回到正轨!
var allQuestions = [{
    question: "Anger can be thought of as a like other feelings and emotions.",
    choices: ["Emotion", "Wave length", "Continuum", "Exercise"],
    correctAnswer: 2
}, {
    question: "Strong, silent type of personality will usually when things finally overwhelm him.",
    choices: ["Explode", "Implode", "Leave", "Cry"],
    correctAnswer: 0
}, {
    question: "People that complain about everything, and see themselves as victims, fit the personality type called.",
    choices: ["Prosecutor", "Grouch", "Exterminator", "Terminator"],
    correctAnswer: 1
}, {
    question: "When someone wants to point out the faults in others, in order to shift blame off of himself, he is probably a",
    choices: ["Displacer", "Intimidator", "Prosecutor", "grouch"],
    correctAnswer: 2
},
{
    question: "The type of personality takes his anger out on people or things he views as “less threatening” than the person he is actually mad at.",
    choices: ["Grouch", "Displacer", "Prosecutor", "Coward"],
    correctAnswer: 1
},
{
    question: "The easiest type of anger personality to spot is usually the.   Often these types come from abusive backgrounds.",
    choices: ["Intimidator", "Grouch", "Displacer", "Prosecutor"],
    correctAnswer: 0
},
{
    question: "Anger has a medical definition, saying it is an state that ranges from to intense fury and rage.",
    choices: ["Mental State Embarrassment", "Emotional State Mild Irritation", "Exhausted State Yawning", "Typical State Relaxing"],
    correctAnswer: 1
},                    
{
    question: "Anger is often compared to a",
    choices: ["Flock of Geese", "Chord of Wood", "Pressure Cooker", "Bag of Ice"],
    correctAnswer: 2
}, 
{
    question: "Anger and rage can become a form of .  These people are known as rageaholics.",
    choices: ["Addiction", "Skin Disease", "Problem", "Comfort Zone"],
    correctAnswer: 0
},                     
{
    question: "First rule When you are   don’t say anything!",
    choices: ["Right", "Wrong", "Angry", "Confused"],
    correctAnswer: 2
},                    
{
    question: "Many times, we feel angry because a situation seems negative, and seems to clash with our.",
    choices: ["Belief System", "Current Plans", "Family Members", "Schedule"],
    correctAnswer: 0
},                    
{
    question: "Many people carry beliefs, that keep them feeling victimized all of the time.",
    choices: ["Stoic", "Unusual", "Irrational", "Western"],
    correctAnswer: 2
}, 
{
    question: "To contain anger, all we have to do is learn to view life from a perspective.",
    choices: ["Personal", "Different", "Closed", "Unknown"],
    correctAnswer: 1
},                     

];

//you can access checkbox name through an array
//match array number to number in allQuestions array

var questionNum = 0;
var scoreNum = 0;
var makeQuestions = "";
var failedQuestions = [];

$(document).ready(function () {
    makeQuestions = function () {
        if (questionNum === allQuestions.length) {
            $("input[value=SUBMIT]").remove();
            $("#questions").text(" All Complete!") .append("<br> Please click the button below to submit your results.") .append("<br>Your score is" + " " + scoreNum);
            $("#questions").append("<br><input type='button' id='submit_answers' value='SUBMIT'><br><br>");
            $("#answers_correct").val(scoreNum);
            $("#questions").append("Failed questions: " + failedQuestions.join());
        } else {
            $("#questions").text(allQuestions[questionNum].question);
            for (var i = 0; i < allQuestions[questionNum]['choices'].length; i++) {
                $('#words').append('<input type="radio" name="buttons">' + allQuestions[questionNum]['choices'][i] + '</input');
            }
        }
    }
    makeQuestions();


    $('#submit_answers').on('click', function () {
        $('#answer_submission_form').submit();
    });

});



var checkQuestions = function () {
    var lenG = document.getElementsByName("buttons").length;
    console.log(lenG);
    var rightAnswer = allQuestions[questionNum]['correctAnswer'];
    for (var i = 0; i < lenG; i++) {
        if (document.getElementsByName("buttons")[i].checked === true) {
            console.log(i);
            console.log(document.getElementsByName("buttons")[i].checked);
            //compare value to what was inputted
            if (i === rightAnswer) {
                scoreNum += 1;
                alert("Correct! Your score is" + " " + scoreNum);
            } else {
                failedQuestions.push(questionNum);
                alert("False! Your score is still" + " " + scoreNum);
            }
        }


    }
    questionNum = questionNum + 1;
    $("#words").empty();
    makeQuestions();

}