user782104
user782104

Reputation: 13555

Only allow to click the submit button, to submit the form

I would like to enter the form , when press enter the input box , it will submit the form

$('input[type=text]').keypress(function(event) {
    if(event.which == 13) {
        //enter pressed
        active($(this));
    }
});

Test it on android mobile, but the keypress can not detect the keycode

How to block this behavior? Thanks a lot

Upvotes: 0

Views: 39

Answers (2)

A.D.
A.D.

Reputation: 2372

$("input:text").keypress(function(event) {

        if (event.keyCode == 13) {
               event.preventDefault();
               active($(this));
        }
});

There we use preventDefault to block his default behavior.

Upvotes: 1

Casper
Casper

Reputation: 1539

$('input[type=text]').keydown(function(event) {

  var keyCode = event.keyCode || event.which; 

  if (keyCode == 13) { 
    active($(this));
  } 

});

Upvotes: 1

Related Questions