Simple validation event on click of a button?

  • 0
    Hello everyone. Please help me to correctly make the validation event when clicking on the button.
    <form action="">
        <input type="text" class="test-input" id="testInput">
        <input type="submit" id="proverka" value="Отправить" onclick="SendPost();">
      </form>
    
      <script>
        function SendPost() {
    
          testInput.addEventListener('keyup', function (event) {
    
            let length = this.value.length
    
            if (length < 9) alert('Заполните')
            else(
              alert('Все заполнено')
            )
          })
    
        }
      </script>
    JavaScript Adalyn Wallace, Jun 1, 2020

  • 1 Answers
  • 0
    1) the simplest is the required attribute, you add it to the input

    2) If via js, then

    let input = document.querySelector("#testInput");
    let length = input.value.length;
    if (length < 9) alert('Заполните')
    else(
    alert('Все заполнено')
    )
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!