Search code examples
htmlformssend

Sending the form without the submit button


I making pagination and I want insert in text field in form number a page and form will send when user press enter or will move the cursor out of the text field.

<form method="GET" action="/site">
<input type="text" name="page" />
</form>

How do I solve this problem?


Solution

  • You can do this with pure Javascipt. Here is a rough pseudo-code to start you off inside IIFE:

    <form method="GET" action="/site">
        <input type="text" name="page" id="yourInput" />
    </form>
    
    <script>
    (function() {
        var el = document.getElementById('yourInput'); //Get your input by ID
        el.onblur = function() { // when focus lost...
            this.form.submit(); // submit the form
        }
    })();
    </script>