如何通过按钮添加表单元素?

时间:2019-03-04 17:57:42

标签: javascript html forms text-files

我正在编写一个问答制造者输入表格,该表格可以响应用户所需的问题数量。这些测验将根据学生的年级和班级进行分组,通过从文本文件读取的响应菜单进行设置。用户可以通过在测验中创建“主题”并将其分组来添加该文本文件。我想在表单底部创建一个按钮,用于复制“问题”,“ answer1”,“ answer2”和“ answer3”的输入字段。

<html>
<head>
<title>Quiz Form</title>
<link rel=“stylesheet” href=“TRYstyle.css”>
</head>

<body>

<h3>Quiz form</h3>

<table>
  <form onSubmit=“WriteToFile(this.txt)>
    <tr>
    <td>Year</td>
    <td>
    <select name="Year" id="schoolyear">
    <option value="1">7</option>
    <option value="2">8</option>
    <option value="3">9</option>
    <option value="4">10</option>
    <option value="5">11</option>
    <option value="6">12</option>
    <option value="7">13</option>
    </td>
    </tr>

    <tr>
    <td>Class</td>
    <td>
    <select name=“group” id=“group”>
    <option value="1">H</option>
    <option value="2">E</option>
    <option value="3">A</option>
    <option value="4">R</option>
    <option value="5">T</option>
    </td>
    </tr>

    <tr>
      <td>Topic</td>
      <td><input type=“text” placeholder=“Topic” name=“topic” id=“topic”  maxlength=“200”/></td>
    </tr>

    <tr>
      <td>Title</td>
      <td><input type=“text” placeholder=“Title” name=“title” id=“title”  maxlength=“200”/></td>
    </tr>

    <tr>
      <td>Question</td>
      <td><input type=“text” placeholder=“Question” name=“question” id=“question” maxlength=“200”/></td>
    </tr>

    <tr>
      <td>Answer</td>
      <td><input type=“text” placeholder=“Answer” name=“answer1” id=“answer1” maxlength=“200”/></td>
    </tr>

    <tr>
      <td>Answer</td>
      <td><input type=“text” placeholder=“Answer” name=“answer2” id=“answer2” maxlength=“200”/></td>
    </tr>

    <tr>
      <td>Answer</td>
      <td><input type=“text” placeholder=“Answer” name=“answer3” id=“answer3” maxlength=“200”/></td>
    </tr>

    <td colspan="2">
      <input type="submit" value="Submit">
    </td>
  </form>
</table>


<script>
function WriteToFile(passForm) {

    set fso = CreateObject("Scripting.FileSystemObject"); 
    set s   = fso.CreateTextFile(“using theseee/this.txt", True);

    var year = document.getElementById('year');
    var group = document.getElementById('group');
    var topic = document.getElementById('topic');
    var title = document.getElementById('title');
    var question  = document.getElementById('question');
    var option1 = document.getElementById('answer1');
    var option2 = document.getElementById('answer2');
    var option3 = document.getElementById('answer3');

    s.writeline("Title: " + title);
      s.writeline("Question: " + question);
        s.writeline("Option1: " + answer1);
          s.writeline(“Option2: " + answer2);
            s.writeline("Option3: " + answer3);

              s.writeline("-----------------------------");
    s.Close();
 }


</script>
</body>
</html>

另外,要存储各种“主题”,考虑到菜单对此有所响应,我是否需要创建一个专用于这些主题的文本文件?或者我可以从相关的每个文本文件中读取第一行,并将它们存储在菜单中吗?这样做的最佳方法是什么? 如果这看起来很低,我感到很抱歉,但是我很努力地摆脱所有这些障碍,因为我是新手。

0 个答案:

没有答案