/    Sign up×
Community /Pin to ProfileBookmark

Submitting a form when pressing enter

Hey there, I’m looking for a bit of javascript that will automatically submit a form using enter. The only problem is that there are two submit buttons in my form that do two different things, so is it possible to get a script like this that will specify which button it uses when submitting the form? Thanks for any help.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — Does this help?

<HTML>

<Head>

<Script Language=JavaScript>

function checkSubmit(){

if (event.keyCode == 13){document.forms.Form1.submit()}
}


</Script>

</Head>

<Body onkeypress="checkSubmit()">

<Form name='Form1' method=post action="something.php">

<input type=button value="Submit 1" onclick="test1()"><br>

<input type=button value="Submit 2" onclick="submit()">

</Form>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@Hell_ToupeeauthorMar 02.2005 — It submits the form when you hit enter, but for the first button it comes across (in this case, submit 1).
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — It's only there as an example. You stated you had TWO submit buttons. Nevermind. I have nothing further to offer. I'm unsubscribing from this thread.
×

Success!

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