0

I need the if bottom if statement to run if #nextQ is clicked (like it is currently) or if enter is pressed.

$('input[type=text]').on('keyup', function(e) {
    if (e.which == 13) {
      alert("enter is pressed");
      return true;
    }
});


$('#nextQ').click(function() {
    //me.html validations 
    if (actual == 0 && document.URL.indexOf("me.html") >= 0){ 
       loadNew();
    }

});
mos finn
  • 9
  • 5
  • possible duplicate of [jQuery multiple events to trigger the same function](http://stackoverflow.com/questions/2534089/jquery-multiple-events-to-trigger-the-same-function) – grunk Nov 24 '14 at 10:29

1 Answers1

0

If your input is wrapped in a form and that form has a submit button, it is submitted when you press enter inside the input.

Knowing this you should listen to the submit event:

The form:

<form class="myForm">
    <input name="answer" type="text">
    <button id="nextQ" type="submit">next Question</button>
</form>

JS:

jQuery( '.myForm' ).on( 'submit', function( event ) {
    //me.html validations 
    if (actual == 0 && document.URL.indexOf("me.html") >= 0){ 
       loadNew();
    }
} );
feeela
  • 29,399
  • 7
  • 59
  • 71