473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to disable "Enter Key" to submit?

I want to force the users to click submit to submit the forms. How do I
disable "Enter Key" which will submit the form automatically when they
entered the data in text field then pressed "enter key"
Jul 23 '05 #1
5 33260
http://links.i6networks.com wrote:
I want to force the users to click submit to submit the forms. How do I
disable "Enter Key" which will submit the form automatically when they
entered the data in text field then pressed "enter key"


You can refuse the enter key, so that it doesn't trigger the default
action, as follows.

---
<form action="foo">
<input type="text" onkeypress="return bar(event)">
<input type="submit">
</form>

<script type="text/javascript">
function bar(evt){
var k=evt.keyCode||evt.which;
return k!=13;
}
</script>
---

Note however that this "enter" key behavior isn't standard (and actually
behaves differently across user agents); moreover this won't prevent you
from full server-side checking, as a client can have javascript
deactivated (or even trick your javascript at runtime).
HTH,
Yep.

Jul 23 '05 #2
In article <JX****************@news04.bloor.is.net.cable.roge rs.com>,
Sa***************@alexa.com enlightened us with...
I want to force the users to click submit to submit the forms. How do I
disable "Enter Key" which will submit the form automatically when they
entered the data in text field then pressed "enter key"


Out of curiosity, why?
I've noticed a lot of times, people who want to do this have put code in the
onClick of the submit button when it should really go in the onSubmit of the
form.

If using the enter key breaks your form and you feel the user MUST click a
button, and your users are known to have script enabled (intranet, etc), the
best way to prevent form submission with the enter key is to simply not
supply a submit button, action, or method at all. Have a normal button that
sets those values and submits when clicked (and keypress if you need to meet
accessibility guidelines). This is a great way to require script and a great
way to really piss off internet users. ;) Works well for intranet apps,
though.

--
--
~kaeli~
If a chicken and a half can lay an egg and a half in a day
and a half, how long would it take for a monkey with a
wooden leg to kick the dill seeds out of a pickle?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <JX****************@news04.bloor.is.net.cable.roge rs.com>,
Sa***************@alexa.com enlightened us with...
I want to force the users to click submit to submit the forms. How do I
disable "Enter Key" which will submit the form automatically when they
entered the data in text field then pressed "enter key"


alternatively provide no submit button and a button that sends the form:
<form method="??" action="??">
<input ....
..../>
<input type="button" value="Submit" onclick="this.parent.submit()"/>

</form>
Jul 23 '05 #4
infinull wrote:
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <JX****************@news04.bloor.is.net.cable.roge rs.com>,
Sa***************@alexa.com enlightened us with...
I want to force the users to click submit to submit the forms. How do I
disable "Enter Key" which will submit the form automatically when they
entered the data in text field then pressed "enter key"

alternatively provide no submit button and a button that sends the form:
<form method="??" action="??">
<input ....
..../>
<input type="button" value="Submit" onclick="this.parent.submit()"/>


this.form.submit(), not the this.parent.submit() I presume is what you
intended to say?
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
infinull wrote on 18 aug 2004 in comp.lang.javascript:
alternatively provide no submit button and a button that sends the form:
<form method="??" action="??">
<input ....
.../>
<input type="button" value="Submit" onclick="this.parent.submit()"/>

</form>


include onsubmit="return false" in <form>:
<form onsubmit="return false">
<input/>
<input type="button" value="Submit"
onclick="this.form.submit()"/>
</form>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Job Lot | last post by:
Could someone provide some help or tips on creating “Registration Key” for client application? I am designing an application in VB.Net which will be distributed to our clients. I want my...
2
by: Gernot Frisch | last post by:
Hi, how can I make a program (console) wait for 'any key' to be pressed? For now I used getchar(), which waits for enter-key... -- -Gernot int main(int argc, char** argv) {printf...
1
by: Holger (David) Wagner | last post by:
Hi there, we have an application which is built with several ASCX controls some of which contain form elements (e.g. Textboxes, Buttons etc.) For example: in the top section (one...
2
by: chuckdfoster | last post by:
I have a form that with a datagrid with textboxes and a submit button. When the user is in a textbox and they hit enter to try to go to a different line, instead they submit the form before they...
1
by: Daren Hawes | last post by:
Hi, I have a ASP.NET 1.1 page that in top corner has a login box & button. Then a large form. Users can fill out the form and press enter, but it actually submits the login not the one I...
2
by: Newbie | last post by:
Hi Everyone, ASP.NET 1.x I have a problemette ! I have a datagrid on my web form. When the user hits the enter key whilst any editable field on the form including those in the datagrid...
10
by: Rob | last post by:
For example, how could you programatically "click" on a button in a Form ?
5
by: gflor16 | last post by:
Problem: I have this code to run a word counter. But I have a problem when I hit the enter key, it doesn't give me any output of how many chars or words. ''' <summary> ''' Returns Word...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.