473,573 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 33281
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="ret urn 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.blo or.is.net.cable .rogers.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******@NOSPA M.comcast.net> wrote in message news:<MP******* *************** **@nntp.lucent. com>...
In article <JX************ ****@news04.blo or.is.net.cable .rogers.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.p arent.submit()"/>

</form>
Jul 23 '05 #4
infinull wrote:
kaeli <ti******@NOSPA M.comcast.net> wrote in message news:<MP******* *************** **@nntp.lucent. com>...
In article <JX************ ****@news04.blo or.is.net.cable .rogers.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.p arent.submit()"/>


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

</form>


include onsubmit="retur n false" in <form>:
<form onsubmit="retur n false">
<input/>
<input type="button" value="Submit"
onclick="this.f orm.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
354
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 clients to provide “Registration Key” when they first install the application. Further, I want this “Registration Key” to be unique for each...
2
1639
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 ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
1
1869
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 ascx-control), there is a textbutton in which the user can enter a string to search for. There's link button right next to that textbutton. Then, in the "content...
2
1391
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 are done entering their data. I know this is how it is supposed to work, but is there anyway to disable the enter key from hitting the submit button?...
1
1997
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 want. How can I ensure that the Enter submits the second submit button on the page and not the first? How can I stop enter submitting at all?
2
2501
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 itself, it triggers a submit back to the server.
10
2267
by: Rob | last post by:
For example, how could you programatically "click" on a button in a Form ?
5
2768
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 Count base on spaces ''' </summary> ''' <param name="textToParse"></param> ''' <returns>Integer = Word Count</returns> '''...
0
7741
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7661
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8165
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8026
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6347
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5252
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3692
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1256
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
984
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.