JS Prevent carriage return (enter) key to submit form

Source: Internet
Author: User

How to Prevent carriage return (enter) key to submit a form, in fact very simple, just a word. Onkeydown= "if (event.keycode==13) return false;" Just write this sentence in the from tag.

If you press enter in the page to automatically submit, you can set the return value to prevent auto-commit such as <input id= "q" name= "Q" type= "text" onkeypress= "Javascript:return gosearch ();" > The return value must be false

functionif(window.event.keyCode = =returnfalse;}}

or write directly in the form

<form name= "Form1" action= "action/soft_add_action.php" enctype= "Multipart/form-data" method= "POST" onkeydown= "if (event.keycode==13) return false; "onsubmit=" return Checksubmit (); " >

or refer to the following code:

You can add a form to the "myform.submit ()" function to judge it, just as you would with a normal form, by changing the name of the function.

</body>

Below is a description of Event.keycode in the next JavaScript.

KeyCode 8 = BackSpace BackSpace
KeyCode 9 = Tab tab
KeyCode = Clear
KeyCode = Enter
KeyCode = shift_l
KeyCode = control_l
KeyCode = alt_l
KeyCode = Pause
KeyCode = Caps_lock
KeyCode = Escape escape
KeyCode = Space Space
KeyCode = Prior
KeyCode = Next
KeyCode = End
KeyCode = Home
KeyCode PNs = Left
KeyCode = up
KeyCode = Right
KeyCode = Down
KeyCode = Select
KeyCode = Print
KeyCode = Execute
KeyCode = Insert
KeyCode = Delete
KeyCode = Help
keycode = 0 Equal braceright
keycode = 1 Exclam onesuperior
KeyCode = 2 Quotedbl twosuperior
keycode = 3 section Threesuperior
keycode = 4 Dollar
KeyCode = 5 percent
KeyCode = 6 Ampersand
keycode = 7 Slash braceleft
KeyCode = 8 Parenleft bracketleft
KeyCode = 9 Parenright bracketright
KeyCode = a A
KeyCode = b b
KeyCode = c C
KeyCode = d D
KeyCode = e e eurosign
KeyCode = f F
KeyCode = g g
KeyCode = h H
KeyCode = i I
KeyCode = J J
KeyCode = k K
KeyCode = l l
keycode = M M mu
KeyCode = n N
keycode = o O
KeyCode = P p
KeyCode Bayi = q q at
KeyCode = r R
KeyCode = s S
KeyCode = t T
KeyCode = u u
KeyCode = v V
KeyCode = w W
KeyCode = x x
KeyCode = y y
KeyCode = Z Z
KeyCode = Kp_0 Kp_0
KeyCode = Kp_1 kp_1
KeyCode 98 = kp_2 kp_2
KeyCode = Kp_3 Kp_3
KeyCode = Kp_4 Kp_4
KeyCode 101 = kp_5 Kp_5
KeyCode 102 = Kp_6 Kp_6
KeyCode 103 = kp_7 kp_7
KeyCode 104 = Kp_8 Kp_8
KeyCode = Kp_9 Kp_9
KeyCode 106 = kp_multiply kp_multiply
KeyCode 107 = Kp_add Kp_add
KeyCode 108 = Kp_separator Kp_separator
KeyCode 109 = kp_subtract Kp_subtract
KeyCode = Kp_decimal Kp_decimal
KeyCode 111 = kp_divide Kp_divide
KeyCode = F1
KeyCode 113 = F2
KeyCode = F3
KeyCode = F4
KeyCode = F5
KeyCode 117 = F6
KeyCode 118 = F7
KeyCode 119 = F8
KeyCode = F9
KeyCode 121 = F10
KeyCode 122 = F11
KeyCode 123 = F12
KeyCode 124 = F13
KeyCode = F14
KeyCode 126 = F15
KeyCode 127 = F16
KeyCode = F17
KeyCode 129 = F18
KeyCode = F19
KeyCode 131 = F20
KeyCode = F21
KeyCode 133 = F22
KeyCode 134 = F23
KeyCode 135 = F24
KeyCode 136 = Num_lock
KeyCode 137 = Scroll_lock
KeyCode 187 = Acute grave
KeyCode 188 = Comma semicolon
KeyCode 189 = minus underscore
keycode = Period Colon
KeyCode 192 = numbersign Apostrophe
KeyCode = Plusminus hyphen Macron
KeyCode 211 =
KeyCode 212 = Copyright Registered
KeyCode 213 = Guillemotleft Guillemotright
KeyCode 214 = masculine Ordfeminine
KeyCode 215 = AE AE
KeyCode 216 = cent yen
KeyCode 217 = Questiondown Exclamdown
KeyCode 218 = Onequarter Onehalf threequarters
KeyCode = Less Greater bar
KeyCode 221 = plus asterisk Asciitilde
KeyCode 227 = Multiply Division
KeyCode 228 = Acircumflex Acircumflex
KeyCode 229 = Ecircumflex Ecircumflex
KeyCode = Icircumflex Icircumflex
KeyCode 231 = Ocircumflex Ocircumflex
KeyCode 232 = Ucircumflex Ucircumflex
KeyCode 233 = Ntilde Ntilde
KeyCode 234 = Yacute Yacute
KeyCode 235 = Oslash Ooblique
KeyCode 236 = aring aring
KeyCode 237 = Ccedilla Ccedilla
KeyCode 238 = Thorn Thorn
KeyCode 239 = ETH ETH
KeyCode = diaeresis cedilla currency
KeyCode 241 = Agrave Agrave Atilde Atilde
KeyCode 242 = Egrave Egrave
KeyCode 243 = Igrave Igrave
KeyCode 244 = ograve Ograve Otilde Otilde
KeyCode 245 = Ugrave Ugrave
KeyCode 246 = adiaeresis adiaeresis
KeyCode 247 = ediaeresis ediaeresis
KeyCode 248 = idiaeresis idiaeresis
KeyCode 249 = odiaeresis Odiaeresis
KeyCode = Udiaeresis udiaeresis
KeyCode 251 = ssharp question Backslash
KeyCode 252 = Asciicircum Degree
KeyCode 253 = 3 Sterling
KeyCode 254 = Mode_switch
Use the KeyCode property of the event object to determine the input key value
Eg:if (event.keycode==13) alert ("enter!");
Key-Value Correspondence table
A 0X65 U 0X85
B 0X66 V 0X86
C 0X67 W 0X87
D 0X68 X 0X88
E 0X69 Y 0X89
F 0X70 Z 0X90
G 0X71 0 0X48
H 0X72 1 0X49
I 0x73 2 0X50
J 0X74 3 0X51
K 0x75 4 0X52
L 0X76 5 0X53
M 0X77 6 0X54
N 0X78 7 0X55
O 0X79 8 0X56
P 0X80 9 0X57
Q 0X81 ESC 0X1B
R 0X82 CTRL 0X11
S 0X83 SHIFT 0X10
T 0X84 ENTER 0XD
If you want to use a key combination, you can use Event.ctrlkey,event.shiftkey,event. Altkey to determine if the CTRL key, SHIFT key, and ALT key are pressed.

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.