Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter key behavior on a form 1

Status
Not open for further replies.

awingnut

Programmer
Joined
Feb 24, 2003
Messages
759
Location
US
I have a form with an onClick event (javascript) for the submit button. When the button is clicked it works fine. However, when the enter key is pressed, the form is submitted but the javascript is not executed. Is this the way it is supposed to work? If so, what do I need to do to get the enter key to run the javascript as well? TIA.
 
cLFlaVA: Yes.
Code:
<input name="Submit" type="Submit" value="Certify &amp; Submit">

vongrunt:

That would be too easy. Its 'Checkform'
 
The submit form button should be something like:
Code:
<input [COLOR=red]type="submit"[/color] name="whatever" value="Button Text" >

Perhaps you could check that the enter button submits the form when there is no javascript?

<marc>
 
doh! you ever get that 'post-writing-lag' where your well-constructed post now looks completely out of place because someone posted back first?!

<marc>
 
case sensitivity...
Code:
<input type="[COLOR=red]S[/color]ubmit"
<input type="[COLOR=red]s[/color]ubmit"
it *should* be lower case, but I don't know offhand if this would break expected behaviour.

<marc>
 
manarth:

It was worth a try. Thanks anyway.
 
Ah ha!!! A revelation. I don't know if this is normal behavior or not but the problem is dependent on the field that has focus. If the focus field is a text type the enter key behaves as expected (I didn't try a list field). However, if the focus is a radio button, checkbox or nothing, the enter key is a no-op.
 
this is standard functionality and is expected. you'd have to implement an onkeypress function to test for the enter key on each of your non-text field elements, to submit the form.

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Right now I feel like your signature icon. That's what happens when the tester takes shortcuts and just hits enter on a fresh page expecting something to happen. Thanks.
 
I think all the effort cFlaVa goes through every day! he should have a permanent star :)

JavaScript Beginner at work :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top