/    Sign up×
Community /Pin to ProfileBookmark

Submit Button Problems

I basically want to be able to hit the enter button and have my form submit.
Here is what happens.

I have a form with 1 text box and 1 button. The button looks like so
<input type=button name=cmdTest value=”Click Me” onclick=”DoSOmething();”>

as you can see its type is button, but the same thing happens if i make its
type submit.

Any way when i hit enter the form does seem to sumbit but it seems like it
does not execute the Onclick statement, which is what drives the app and
tells me what action to take, what code to execute, validate, etc.

Im wondering if because when i hit the enter button, its not really a onClick,
because if i click the button with my mouse then it all works fine.

Now if i hit enter twice, the second time it will submit, but not all the time.
But still annoying none the less.

So how do i set these up so that i can hit the enter button yet still be able
to call my functions and have the page submit?

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@BrainDonorJul 22.2005 — Like this?

<html>

<head>

<script type="text/JavaScript">

<!--

function keyDown() {

if (event.keyCode==13) {

DoSomething();

}

}

function DoSomething() {

alert('something');

}

//-->

</script>

<head>

<body>

<input type="text" size="10" value="" onkeydown="keyDown();">

<input type="button" value="Do Something" onclick="DoSomething();" >

</body>

</html>
Copy linkTweet thisAlerts:
@lmf232sauthorJul 22.2005 — actually this is what seems to happen. and i thought about the way you typed it but ran into way to many problems.

Reply to this tread and look at the Submit Reply button below. It has a highlight color to it where as Preview Post does not.

Now it your tab button till you get to the Submit Reply button youll see how you have given it focus.

For Me these seem to be two different things.

For starters when you come into this reply page and see the button with its highlight (same as the buttons on my page) and i hit enter, its submits the

form but it will not fire the onclick="WHatEver();" function.

But if i tab to the button like i mentioned and then hit enter, it all works fine.

But on this site, it you hit enter at anytime it will submit the post.

So im not sure, it seems like the first time i hit enter it submits the form and then gives the button focus which then when i hit enter again it submits the form.

?
Copy linkTweet thisAlerts:
@BrainDonorJul 22.2005 — copy and paste my code into Notepad and save it as "something.html"

open the file and test it. I am not having any problems with it and if I hit enter while in the text area, the focus does not go to the button.
×

Success!

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