/    Sign up×
Community /Pin to ProfileBookmark

Form Submission

Hullo, I’m wondering how I stop a form from being submitted when I hit enter. I want the form to do nothing when enter is typed, to leave all text fields and buttons they way they were. Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mjdamatoDec 29.2006 — I'm assuming you want the user to still be able to submit the form through a button click? Here's one way:

<i>
</i>&lt;form name="formname" id="theform" onsubmit="return false;"&gt;
...form contents....
&lt;button onclick="document.getElementById('theform').submit();"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
Copy linkTweet thisAlerts:
@ProGrapeauthorDec 29.2006 — Actually, for the moment, the form never gets submitted since the user is given output info as they type. But I think you've given me the right idea, that is, to return false, so I'll go and give it a shot. Thanks ?

Is it possible to define explicity the method onSubmit()?

For instance, could you do something like
[CODE]function onSubmit () {
return false;
}[/CODE]

?
×

Success!

Help @ProGrape 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.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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