In jsp, how does one automatically submit the form by pressing the Enter key? In jsp, the Return key submits the form

Source: Internet
Author: User

In jsp, how does one automatically submit the form by pressing the Enter key? In jsp, the Return key submits the form

In order to save trouble, you often want to press the Enter key to submit the form. to control these actions, you can use JS to meet the requirements.

The Code is as follows:

<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <% @ include file = ".. /.. /common/include_tag.jsp "%> <% @ include file = ".. /.. /common/page_var.jsp "%> <! Doctype html> 

Solution:

Put the form in a div, and then listen to the div event $ ("# id"). keydown (function (){});

# * # Listen to the carriage return event

Document. onkeydown = function () {if (event. keyCode = 13) {// submit your form $ ('# ff_login'). submit ();}}

# * # Compile js scripts on the page for listening...

# * # Js listens to the enter event #*#

Put the form in a div, and then listen to the div event $ ("# id"). keydown (function (){});

# * # Obtain the focus listener enter #*#

Listen to the keypress event of the entire body. If it is a carriage return key, it will trigger the click Event of the submit button. Of course, there will be related data validation in your click event. If it is not verified, it will not be submitted.

I hope this article will help you with jsp program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.