2

I noticed that when I create a button with type=button (on an example login button) to script it with JavaScript without refreshing the page, then I can't press Enter to move forward.

Is there a workaround?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bartłomiej Sobieszek
  • 2,692
  • 2
  • 25
  • 40

1 Answers1

1

$(document).ready(function() {
  $(document).on('keypress', function(e) {
    if (e.which == 13){
      $('.button').trigger('click');
    }
  });
  
  $('.button').on('click', function() {
    alert('hi');
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text"/>
<input type="button" class="button" value="BUTTON"/>
indubitablee
  • 8,136
  • 2
  • 25
  • 49
  • The OP doesn't want a submit button. This is effectively a submit button that is dependent on several thousand lines of script rather than none at all (see answers to [*Submitting a form by pressing enter without a submit button*](http://stackoverflow.com/questions/477691/submitting-a-form-by-pressing-enter-without-a-submit-button)). – RobG Jan 23 '15 at 21:47