DevJourney · code I wrote while learning

index.html

625 B
<!doctype html>
<html>
  <head>
    <script>
      function validateForm() {
        let x = document.forms['myForm']['fname'].value;
        if (x == '') {
          alert('Name must be filled out');
          return false;
        }
      }
    </script>
  </head>

  <body>
    <h2>JavaScript Validation</h2>

    <form
      name="myForm"
      action="/action_page.php"
      onsubmit="return validateForm();"
      method="post"
    >
      Name: <input type="text" name="fname" />
      <input type="submit" value="Submit" />
    </form>

    <p id="time"></p>

    <script src="./time.js"></script>
  </body>
</html>