Skip to content Skip to sidebar Skip to footer

How To Stop Page Refresh On Typing In Form Input?

I'm breaking my head over a small issue. I have a chat box in my web app which contains one input[type='text'] and a button. What I want is whenever user clicks on the button, the

Solution 1:

In order to avoid the submition of the form, you have to add an event.preventDefault() to your submitNewMessage function.

Other way is to remove the form tags.

Solution 2:

To stop the page from reloading when you click the button, try this:

$scope.submitNewMessage = function($event) {
  event.preventDefault();
  // your code
$scope.form.newMessage = ''; // to empty your input afterwards
}

Post a Comment for "How To Stop Page Refresh On Typing In Form Input?"