Home > Web Front-end > JS Tutorial > body text

How to Prevent Clearing Login Forms on Enter Keypress in jQuery?

Barbara Streisand
Release: 2024-10-25 11:35:30
Original
807 people have browsed it

How to Prevent Clearing Login Forms on Enter Keypress in jQuery?

How to Submit a Form on 'Enter' with jQuery

When working with login forms in an AIR project using HTML/jQuery, you may encounter an issue where pressing Enter clears the form's content instead of submitting it. To resolve this, ensure that your code properly handles this event.

The following code should accomplish this:

$('.input').keypress(function (e) {
  if (e.which == 13) {
    $('form#login').submit();
    return false;    //<---- Add this line
  }
});
Copy after login

The key point here is adding the "return false" statement. This prevents the default action (clearing the form) from occurring while allowing the submit event to be triggered.

For more detailed information on this topic, refer to the stackoverflow answer on the subject of "event.preventDefault() vs. return false".

The above is the detailed content of How to Prevent Clearing Login Forms on Enter Keypress in jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!