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

Using the enter key to submit a form

Status
Not open for further replies.

nevets2001uk

IS-IT--Management
Jun 26, 2002
609
0
0
GB
Not sure what's causing this but on SOME of my asp forms pressing enter (return) while in one of the text boxes does not submit the form (i.e. fire off the click event for the form's button).

Some forms such as my login form work fine, but others do not. Is there a possible reason for this that anyone can think of? I've checked the code for pages that work and pages that don't and they seem to be the same.

All ideas welcomed.

Cheers!

Steve Gordon
 
Hi there,
You need to set focus to the submit button. If your page has only one button, then the focus is set on that button by default, but if your page has several buttons, then it might be set to some other button.

Use javascript to set the focus on the desired button, but this doesn't work on Netscape 4.7. Anyone know how to make it work on Netscape 4.7?
 
The thing is that it's happening even on forms with only one button. In fact all my forms only have one button, but still I'm getting the problem.

Do you know the javascript that I should use to get this to work? This is an ASP form with ASP controls.

Thanks.

Steve Gordon
 
this is what I'm using, insert it into your HTML:
(note that "btnSubmit" is your submit button id)

<HEAD>
<script lang=&quot;Javascript&quot;>
function onkey()
{
if(window.event.keyCode==13){
document.getElementById(&quot;btnSubmit&quot;).focus();
}
}
</script>
</HEAD>
<body onkeydown=&quot;onkey();&quot;>
 
Thanks!

The only thing is I'm using vb.net asp code and I'd heard that you can't / shouldn't mix languages on a page. Is this going to create any know problems?

Steve Gordon
 
you put the javascript code in your .aspx page. It's quite standard to use javascript with vb.net in ASP.Net. Afterall, the client-side script that ASP.NET uses is javascript.

cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top