jquery - How to press enter in input type text call function javascript by not submit form? -


how press enter in input type text call function javascript not submit form ?

when fill data input type text , press enter keyboard want call function detect_enter_keyboard(event) not submit form.

how can ?

https://jsfiddle.net/atuyx7qc/

<form> <input type="text" name="user" onkeypress="detect_enter_keyboard(event)"> <input name="btnlogin" onclick="test_fn();" type="button" value="send"> </form>  <script> function detect_enter_keyboard(event) {     var key_board_keycode = event.which || event.keycode;     if(key_board_keycode == 13)     {         test_fn();     } } </script>  <script> function test_fn(){ alert("555555"); } </script> 

with preventdefault(). add line after if(key_board_keycode == 13):

event.preventdefault(); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -