Use Ctrl + enter in ASP to submit a form

Source: Internet
Author: User

Solution:
Capture the key event in the form and determine whether to press Ctrl or enter. If yes, submit the form using the submit method of the form.

<Form action = "test. asp" onkeydown = "If (event. ctrlkey & event. keycode = 13) This. Submit ()">
<Textarea name = "content"> </textarea>
</Form>

Tip: Besides onkeydown, the event handle of the buttons also includes onkeyup and onkeypress. You can use event. ctrlleft to determine the ctrl key on the left.

<HTML>
<Head>
<Title> Ctrl Enter submit </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Script language = "JavaScript">
Function checkform ()
{
If (document.myform.txt name. value = "")
{
Alert ("file name cannot be blank! ");
Document.myform.txt name. Focus ();
Return false;
}
Return true;
}

Function quicksubmit ()
{
If (event. keycode = 13 & event. ctrlkey)
{
If (checkform ())
{
Document. myform. Submit ()
Return true
}
Else
Return false
}
}
</SCRIPT>
</Head>

<Body bgcolor = "# ffffff" text = "#000000" onkeydown = "Return quicksubmit ()">
<Form name = "myform" method = "Post" Action = "work_edit2.asp">
<P> File Name:
<Input type = "text" name = "txtname">
</P>
<P> description:
<Textarea name = "txtareanote"> </textarea>
</P>
<Input type = "Submit" name = "Submit" value = "Submit" onclick = "Return checkform ()">
(CTRL + enter submit)
</Form>
</Body>
</Html>

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.