<form onsubmit="return false;"><input
type="submit" value="won't do
shit" /></form>
On 2/5/06, christoph breidert.net <christoph breidert.net> wrote:
>
> Hi Folks,
>
> spent some hours on this could not find a solution. I
want to prevent
> submission of a form, when ENTER is hit (keycode 13). I
could not
> achieve this with firefox (my favourite browser), works
fine with other
> browsers. Is this a bug? Is there a workaround?
>
> I do not like this solution:
> http://groups.google.com/group/mozilla-firefox/browse_
thread/thread/3e83f1f91ca8f70f/50fd39f5ff40c0ee#50fd39f5ff40
c0ee
>
> Here is my testcode:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
> "http:/
/www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <title>Test</title>
> <script language="Javascript">
> function Test(elem){
> elem.onkeydown = function(e) {
> if (!e) var e = window.event;
> if(e.keyCode==13){
> e.returnValue=false;
> e.preventDefault();
> e.stopPropagation();
> alert("ENTER");
> }
> return false;
> }
> }
> </script>
> </head>
> <body>
> <form>
> <input type="text"
name="test" id="test" />
> <script
language="Javascript">new
> Test(document.getElementById('test'));</script>
> <input type="submit" />
> </form>
> </body>
> </html>
>
> Thanks for help.
>
> Cheers, Christoph
>
>
|