/    Sign up×
Community /Pin to ProfileBookmark

disabling enter key for form submission

is there an easy way to disable the enter key for submission of a form???

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PineSolPirateMar 09.2007 — This works in firefox at least.
[code=php]document.captureEvents(Event.KEYPRESS);
document.onkeypress = function (e) { if(e.which == 13) { return false; } }[/code]
Copy linkTweet thisAlerts:
@bcamp1973authorMar 09.2007 — works for me in safari too. thanks! crossing fingers that it also works in InternetExploder...
Copy linkTweet thisAlerts:
@bcamp1973authorMar 09.2007 — argh! of course not. i'm getting the "Event" is undefined error...
Copy linkTweet thisAlerts:
@samanyoluMar 09.2007 — <i>
</i>&lt;form action="foo"&gt;
&lt;input type="text" onkeypress="return bar(event)"&gt;
&lt;input type="submit"&gt;
&lt;/form&gt;

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

http://www.hotspot.freeserve.co.uk/scripterlative/?entertotab
×

Success!

Help @bcamp1973 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,
)...