Home>
Thing I want to do

I want to issue an alert with javascript if nothing is entered in the input form created in HTML

code in index.html
<! DOCTYPE html>
<html>
<head>
  <meta charset = "UTF-8">
  <title>sample</title>
</head>
<body>
  <form name = "form1" action = "cgi-bin/example.cgi" method = "post">
      <p>Enter the keyword I want to search.</p>
      <input type = "search" name = "search" placeholder = "Enter keyword">
      <input type = "submit" name = "submit" value = "search">
  </form>
  <script type = "text/javascript">
        function check () {
            if (document.form1.search.value == "") {
                alert ("Please enter something");
                return false;
            }
            else {
                return true;
            }
        }
  </script>

</body>
</html>
What I tried

In order to check if js itself works, I tried to describe it appropriately as follows, but it worked here.

<script>
        alert ("No")
  </script>
Finally

I'm a beginner of html/js, so I think there are many things I don't understand, but please give me some advice.

Reference article