<?php
/* Disable the enter key
*/
?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>Confirmation Dialogue
Boxes</title>
<script type=
"text/javascript"
>
//create a function that
accepts an input variable (which key was key pressed)
function
disableEnterKey(e){
//create a variable to hold
the number of the key that was pressed
var
key;
//if the users browser is
internet explorer
if
(window.event){
//store the key code (Key
number) of the pressed key
key = window.event.keyCode;
//otherwise, it is firefox
}
else
{
//store the key code (Key
number) of the pressed key
key = e.which;
}
//if key 13 is pressed (the
enter key)
if
(key == 13){
//do nothing
return
false;
//otherwise
}
else
{
//continue as normal (allow
the key press for keys other than "enter")
return
true;
}
//and don't forget to close
the function
}
</script>
</head>
<body>
<form>
<!-- Here we have a form field with
it's
"onKeyPress"
event set to call our JavaScript
function
-->
<input type=
"text"
name=
"mytext"
onKeyPress=
"return
disableEnterKey(event)"
>
</form>
</body>
</html>
<?
/* Tutorial by Marc Firth
*/
?>
沒有留言:
張貼留言