how to automatic trigger the enter button after switching to next input text

hello guys i need to automatic trigger the enter button after the user switch to another html input type='text'. i need to do this so that i can validate the form.

here is my code:

<input type="text" class="form-control input-sm" name="student_lastname" placeholder="Last Name" pattern="[A-Za-z].{1,}" title="Only Letters are accepted and more than 1 letter" required>

i need the error title="Only Letters are accepted and more than 1 letter" to pop up when the user is finished typing to the box

right now this is what my code looks like

Answers 1

  • onblur is the perfect solution, and was made specifically for when the user leaves an input field. Just do something like this:

    For HTML:

    <input type="text" onblur="validate()" />
    

    And for JS:

    function validate() {
      // This is how you automatically make them click the Enter button:
      enterButton.click();
    }
    

Related Articles