/    Sign up×
Community /Pin to ProfileBookmark

How to prevent form submit mistake?

Hi all,
How do I prevent user hits a return key to submit instead of the tab key to move between fields? Thanks for any advice.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@buntineJul 21.2004 — Moved to correct forum.
Copy linkTweet thisAlerts:
@KorJul 21.2004 — Try this:

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function ekey(w,f,e){
if(typeof event!='undefined'){
var pressedkey=window.event.keyCode;
}else{
var pressedkey=e.keyCode;
}
if(pressedkey==13){
for(var i=0;i<f.elements.length;i++){
if(w.name==f.elements[i].name){
f.elements[i+1].focus();
return false
}
}
}
}
//-->
</script>
</head>

<body>
<form>
<input type="text" name="t0" size="30" onkeypress="return ekey(this,this.form,event)" /><br>
<input type="text" name="t1"size="30" onkeypress="return ekey(this,this.form,event)" />
<br>
<input type="checkbox" name="checkbox" value="checkbox" onkeypress="return ekey(this,this.form,event)">
<br>
<input type="text" name="t2" size="30" onkeypress="return ekey(this,this.form,event)" /><br>
<input name="sub" type="submit">
</form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@omygodauthorJul 21.2004 — Thank you Kor. It is exactly what I needed.
Copy linkTweet thisAlerts:
@KorJul 22.2004 — you're welcome here whenever you have a problem and, all uf us, if we are able to, we will solve it ?
×

Success!

Help @omygod 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...