SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
May 29, 2002, 07:57 #1
- Join Date
- May 2002
- Posts
- 32
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Disabling enter key in form fields
Does anyone know how I can keep the enter key from submitting a form in IE? I'm writing a page that switches from text to an input box, and then back to text when the user presses enter. I'm trying something with the onkeypress event, but I can't figure out exactly what to do.
Thanks,
Joe Fiorini-Joe
-
May 29, 2002, 08:05 #2
- Join Date
- May 2002
- Posts
- 32
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
cool
Yay! I figured it out. Here's the code I used:
[VBS]
var FormKey;
function FormKeyHandler(){
FormKey = window.event.keyCode;
return true;
}
function FormSubmit(){
return FormKey != ekeyEnter;
}
<form id="frmEditFolder" action="CreateFolder.asp" onSubmit="return FormSubmit();" onkeypress="return FormKeyHandler();">
[/VBS]
Does anyone know of a better way to do this?
Thanks,
Joe-Joe
-
May 29, 2002, 16:30 #3
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yes, i made a key capture script a while back.
if you push enter or b or p it will print either a <br> or <p> in the box
i doubt the site will load as port5.com is crap
http://andrew-j.port5.com/test/keyCapture.html
if not heres the code
PHP Code:
<script>
function keyCapture()
{
if (event.keyCode == 13)
{
Output.innerText+='<br>';
event.returnValue=false;
}
else if (event.keyCode == 80)
{
Output.innerText+='<p>';
event.returnValue=false;
}
else if (event.keyCode == 66)
{
Output.innerText+='<br>';
event.returnValue=false;
}
else
{
Output.innerText+=' key : ' + event.keyCode + ' ';
event.returnValue=false;
}
}
</script>
<input type="checkbox" id="Trap" checked>
<input type="text" id="txt" onkeydown="keyCapture()" size="60"><br>
<textarea id="Output" rows="30" cols="50"></textarea>
Bookmarks