html - Submiting a form with jquery -
i trying submit form when enter key in textarea pressed. seems should work, doesn't. alert, , refreshes page, doesn't submit form. whats wrong it? thanks! clarify, want pressing enter key exact same thing hitting submit button.
<?php //doing stuff submitted form ?> <form id='myform' action='' method='post'> <tr> <td><textarea id='but' class='messin' name='mess' placeholder='reply...'></textarea></td> <td><input class='messin' type='submit' name='submit' value='send'/></td> </tr> </form> <script type="text/javascript"> $(document).ready(function(){ $("#but").keyup(function(event) { if (event.which == 13) { event.preventdefault(); alert("submit!"); $("#myform").submit(); location.reload(); } }); }); </script>
remember .submit() not blocking operation. means if call after causes navigation modification, abort submission. try not reloading page.
btw submission means (synchronous) redirection. if intention submit ajax form (which not automatically redirect), should reload in complete
callback of ajax call.
Comments
Post a Comment