Disable Keys in Forms

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

Is it possible to disable a form submission when the Return key is
pressed?

I want the form to be submitted only when a button is pressed.

Thank you,

Miguel
 
Hi,
You can write following javascript function:

<script language=javascript>
document.onkeydown = function(){
if(window.event && window.event.keyCode == 13)
{
return false;
// or else you can also write window.event.keyCode =0
}
}

Thanks and Regards,
Manish Bafna.
MCP and MCTS

</script>
 
You can write following javascript function:

<script language=javascript>

That syntax is not XHTML-compliant...
document.onkeydown = function(){
if(window.event && window.event.keyCode == 13)
{
return false;
// or else you can also write window.event.keyCode =0
}
}

That will only work in IE...

<script type="text/javascript>

document.onkeyup = function keyPress(evt)
{
if(document.all)
{
var whichKey = window.event.keyCode;
}
else
{
var whichKey = evt.which;
}
if(whichKey == 13)
{
return false;
}
}

</script>
 
Hi Mark,

I tried your code but it does not work.

I found this one:

function checkCR(evt) {

var evt = (evt) ? evt : ((event) ? event : null);

var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);

if ((evt.keyCode == 13) && (node.type=="text")) {return false;}

}

document.onkeypress = checkCR;

It works but when the cursor is inside a password text box it does not
work.
So I removed (node.type=="text") and now it works both in Firefox and
IE and also for password type textboxes.

What do you think?

Thanks,
Miguel
 
I don't get an error. The form just submits itself when I press Return.

Any idea?

Thanks,
Miguel

P.S: The code I posted works only in Firefox. It seems it does not work
in IE either.
 
I don't get an error. The form just submits itself when I press Return.

Any idea?

Yes - see below...
P.S: The code I posted works only in Firefox. It seems it does not work
in IE either.

Then you've almost certainly set it up incorrectly...

Is the page in question available on the public internet...?
 
Back
Top