Disable Enter Key

S

Stephen

Hi,

How do I disable the enter key for a "Form"? so that user has to click the
"Submit" button.
Is there a way of doing it other than using Java/VB script?

Thanks,
Stephen
 
A

Anushi

Hi Stephen,
Include this function on the page
function disableEnterKey()
{
if (window.event.keyCode == 13) window.event.keyCode = 0;
}
Then any form you wish to disbale the enter key on, use the following:
<form name="form" method="post" action="" onKeyPress="disableEnterKey()">

This can also be achieved by submitting the form using the onClick event
handler instead of onSubmit event handler. It is necessary to return false
on event handler onSubmit to prevent submit on hitting ENTER key. Sample
code:
<form name="form1" onSubmit="return false">
<input type="text">
<input type="button" value="SubmitForm" onClick="document.form1.submit()">
<a href="#" onClick="document.form1.submit()"><img src="button.gif"></a>
</form>For a Javascript version, refer here
:http://javascript.internet.com/forms/tab-key-emulation.htmlHope this
helps.Regards,Anushi
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top