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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't submit form when ENTER key pressed

Status
Not open for further replies.

cawthor

Programmer
May 31, 2001
89
US
I have a form with various text boxes. When a user presses the ENTER key whilst in one of the text boxes, the form is submitted. Can I disable this and just move the tabindex to the next text box? I don't want the form to submit until the user clicks on the 'Submit' button.

Thanks.
 
works in IE 6.0.2800 and FF 1.0.6:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<html>
<head>
<title>new document</title>

<script language="javascript" type="text/javascript">
<!--

function tabNext(e, i) {
    if (e.keyCode == 13)
	    document.forms['f'].elements[i].focus();
	return false;
}

-->
</script>

<style type="text/css">

</style>

</head>

<body>
<form name="f">

  <input type="text" name="t1" onkeypress="return tabNext(event, 't2');" /><br />
  <input type="text" name="t2" onkeypress="return tabNext(event, 't3');" /><br />
  <input type="text" name="t3" onkeypress="return tabNext(event, 't4');" /><br />
  <input type="text" name="t4" onkeypress="return tabNext(event, 's');" /><br />
  <input type="submit" name="s" />
</form>
</body>

</html>

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
cLFlaVA
What happens if the next element does not have the ability to get the focus? Does it go to the next or do we lose the position in the tab order and start at the beginning again?

Guess I could try it out. Just trying to avoid any REAL thought until after lunch.

Paranoid? ME?? WHO WANTS TO KNOW????
 
well the way i coded this was to expicitly state what you want the "next element" to be.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
Well see, that's where the not thinking until after lunch kicks in.
I scan the code but do not digest it. Digestion will not occur again until after I get some food.


Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top