/    Sign up×
Community /Pin to ProfileBookmark

Is there a way I can disable the enter key from submitting a form? You can use the tab key to go from one text box to another but sometimes people press the enter key.

Thanks

to post a comment
Full-stack Developer

13 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 12.2003 — [font=georgia]But what about the people who press then enter key because they want to submit the form? And what about those who have no mouse and no other way to submit the form?[/font]
Copy linkTweet thisAlerts:
@ashersauthorAug 12.2003 — What about them? That wasnt my question? I was just asking if it can be done.
Copy linkTweet thisAlerts:
@CharlesAug 12.2003 — [font=georgia]And if I were to ask you for the best way to take a white cane from a blind person waiting for the bus, would you tell me?

It is customary, when someone is about to cause some unintentional harm, to warn them. Kind people welcome such information.[/font]
Copy linkTweet thisAlerts:
@ashersauthorAug 12.2003 — Maybe it would be more helpful to stop assuming that what I am trying to do will be available for all of the web if much at all. You seem to jump to conclusions, people shouldn't have to justify there questions, they are questions that have been asked for a valid reason.
Copy linkTweet thisAlerts:
@AdamBrillAug 12.2003 — [i]Originally posted by Charles [/i]

[B][font=georgia]And if I were to ask you for the best way to take a white cane from a blind person waiting for the bus, would you tell me?[/font] [/B][/QUOTE]
Yes, I would. :p j/k, lol

Give him a break, Charles...

ashers, here is an example of something close to what you are looking for:<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function key_pushed(event){
if(event.keyCode==13){
event.keyCode=9;
}
}
</script>
</head>
<body onKeyDown="key_pushed(event);")>
<form>
<input type=text>
<input type=text>
<input type=submit>
</form>
</body>
</html>
If you press the <enter> key, it will act as if you pushed the <tab> key instead. Charles should be happy, too, because it will work like normal for people without JS. ?
Copy linkTweet thisAlerts:
@ashersauthorAug 13.2003 — Thanks, exactly what I needed.
Copy linkTweet thisAlerts:
@PeOfEoAug 13.2003 — charles I know that we should try to design for everyone or atleast make sites compadable for as many as possible but how many people without a mouse are going to visit the average low traffic site? Unless it is a site that sells mouses then I would think none. Some times sacrafices must be made and you then have to look at the numbers because you cant look at each indovidual person and you weigh the numbers... which option will inconveiniance the least amount of people. But that is just my view of things like that.
Copy linkTweet thisAlerts:
@ashersauthorAug 14.2003 — And in this case it was intended for about 20 specific people.
Copy linkTweet thisAlerts:
@AdamBrillAug 15.2003 — Since you never know the whole situation, I like to give people the answer and then warn them that it won't work for all users(however, in this case, it will work for all users).It is customary, when someone is about to cause some unintentional harm, to warn them. Kind people welcome such information.[/QUOTE]I fail to see the "unintentional harm" in this case. My code will work exactly normal for anyone that doesn't have JS...
Copy linkTweet thisAlerts:
@CharlesAug 15.2003 — [font=georgia]The harm is caused to the people who do use JavaScript but who aren't using a mouse or who are used using a browser. Some poeple need and some people want the form to submit when the enter keyu is pressed.[/font]
Copy linkTweet thisAlerts:
@ashersauthorAug 15.2003 — I don't think you get the point though, I thought this forum was for learning things, not a place where you lay down the law on what people should and shouldn't do. I'd rather just help people in what they are trying to do and leave it up to them to decide how they implement it. The use that I wanted to put my question to was for around 20 people who are not blind and who have a mouse, so I didn't really need advice on that.
Copy linkTweet thisAlerts:
@AdamBrillAug 15.2003 — Charles, what do you think about this one?&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled&lt;/title&gt;
&lt;script type="text/javascript"&gt;
function key_pushed(event){
if(event.srcElement.type != "submit" &amp;&amp; event.keyCode==13){
event.keyCode=9;
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onKeyDown="key_pushed(event);")&gt;
&lt;form action="wherever.php"&gt;
&lt;input type=text&gt;
&lt;input type=text&gt;
&lt;input type=submit&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
That way it will submit it if they are on the submit button and they hit the enter key, but the rest of the time it acts like a tab. Unless I forgot something, this should work for everyone, even if they have JS but don't have a mouse. Am I correct?
Copy linkTweet thisAlerts:
@CharlesAug 15.2003 — [font=georgia]That one's not so bad.

I do have one concern though. People get used to the way that the user interface works on their browsers. Messing with that will certainly not make them happy. I'ts not just an annoyance issue but we have to keep in mind persons with cognitive disabilities who might get confused if you change the way the interface works. In a kiosk situation it might work but in other situations I would be careful.[/font]
×

Success!

Help @ashers spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...