user11211072
user11211072

Reputation:

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?

Upvotes: 2

Views: 132

Answers (1)

Dharman
Dharman

Reputation: 33237

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>

Upvotes: 3

Related Questions