Help with Enter key and disabling button click

D

David Hearn

I have a javascript function that is fired on the KeyDown event of a
textbox. I am adding the attribute to the textbox at page load to run this
javascript function. The javascript runs as expected and the text box that
is specified in the javascript gets the focus set to it, but my problem is
that the default button on the form is being pressed also so once the
textbox gets the focus, you barely see it before the page redirects. I want
this javascript to run and to somehow cancel out the button click event.
Anyone know how?

Thanks in advance!

function GetEnter() {
if (event.keyCode == 13) // If key that was pressed is Enter key
document.Form1.txtPartNumber2.focus(); //Set focus to txtPartNumber2
}
 
T

Teemu Keiski

Hi,

what if after setting the focus to the textbox you'd call 'return;' or
'return false;' (I don't now remember did they behave differently, but try
both of them). It should prevent the butting being activated & pressed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top