首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >表单上的Javascript验证

表单上的Javascript验证
EN

Stack Overflow用户
提问于 2022-05-05 12:14:51
回答 1查看 350关注 0票数 0

刚从HTML和JavaScript开始,就设置了一个任务,用于某些逻辑函数使用JavaScript。我已经创建了一个表单,并希望检查这些元素是否已正确填写。我试图查看期限,理想情况下希望在提交时设置一个最小值,但是它并不像预期的那样工作。

我必须为赋值使用codepen,它为JavaScript有一个单独的列,但是我已经将使用的代码放在表单中,不确定我需要做什么。

任何帮助都将不胜感激。

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Student recovery recording</title>
    <link rel="stylesheet" href="newstyle.css" />
    <meta charset="UTF-8" />
  </head>
  <body>
    <header><h1>Student Recovery Recording</h1></header>
    <main>
      <div class="container1">
        <p>form content goes here</p>
      </div>
      <div class="container">
        <form name="myForm" form action="" method="get">
          <div class="form-row">
            <label for="name"> Instructor Name:</label>
            <input type="text" id="name" />
          </div>
          <div class="form-row">
            <label for="Exam"> Exam Code:</label>
            <select name="Exam" id="Exam">
              <option value="">--Please choose the correct Exam code--</option>
              <option value="code1">AT017</option>
              <option value="code2">CT154</option>
              <option value="code3">AT317</option>
              <option value="code4">BT141</option>
            </select>
          </div>
          <div class="form-row">
            <label for="reason"> Reason For Training:</label>
            <select name="reason" id="reason">
              <option value="">
                --Please select the correct reason for training
              </option>
              <option value="train1">ATT</option>
              <option value="train2">ITT</option>
              <option value="train3">ETT</option>
            </select>
          </div>
          <div class="form-row">
            <label for="date">Date:</label>
            <input type="date" id="date" />
          </div>
          <div class="form-row">
            <label for="Studentname"> Student Name:</label>
            <input type="text" id="Studentname" />
          </div>
          <div class="form-row">
            <label for="Duration">Duration:</label>
            <input type="time" id="Duration" min="1:00" />
          </div>
          <div class="form-row">
            <textarea name="comment" rows="4" cols="50">
Enter details of work carried out and KLP's covered here...</textarea
            >
          </div>
          <input type="submit" value="Submit" onclick="myFunction()" />
          <script>
            function myFunction() {
              var text;
              if (document.getElementById("Duration").validity.rangeUnderflow) {
                text = "Not enough Recovery Time";
              } else {
                text = "Recovery Time acceptable";
              }
              document.getElementById("myForm").innerHTML = text;
            }
          </script>
        </form>
      </div>
    </main>
    <footer>
      <p>
        <a href="http://jigsaw.w3.org/css-validator/check/referer">
          <img
            style="border: 0; width: 88px; height: 31px"
            src="http://jigsaw.w3.org/css-validator/images/vcss"
            alt="Valid CSS!"
          />
        </a>
      </p>
    </footer>
  </body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2022-05-05 12:52:00

也许您可以使用setTimeOut()方法来设置持续时间,在用户加载窗口或用户开始按键时触发该方法。

示例:

代码语言:javascript
复制
      <div class="form-row">
        <label for="name"> Instructor Name:</label>
        <input type="text" id="name" onkeypress="setTimeout(showSubmitButton(), 5000)" /> //trigger showSubmitButton() when key pressed wait 5 sec then run showSubmitButton()
        <input type="submit" id="submit" value="submit" style="display:none">// set display to none for hiding the button
      </div>
      <script>
      function showSubmitButton() {
        document.getElementById("submit").style.display = "block" // show the button after 5 sec
      }
      </script>

希望这对你有帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72127004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档