顯示具有 disable enter 標籤的文章。 顯示所有文章
顯示具有 disable enter 標籤的文章。 顯示所有文章

2012/09/16


<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form name="frmMain" action="" method="post">
<script language="JavaScript">
document.onkeydown = chkEvent
function chkEvent(e) {
 var keycode;
 if (window.event) keycode = window.event.keyCode; //*** for IE ***//
 else if (e) keycode = e.which; //*** for Firefox ***//
 if(keycode==13)
 {
  return false;
 }
}
</script>
Textbox 1 <input type="text" name="txt1" value=""> <br>
Textbox 2 <input type="text" name="txt2" value=""> <br>
Textbox 3 <input type="text" name="txt3" value=""><br>
<input type="submit" name="btnSubmit" value="Submit">
</form>
</body>
</html>

<?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 */ ?>