Recently i faced issue with key code. I just tried to restrict user by entering unwanted special characters by using jQuery validation but I faced issue with browser compatibility. Actual scenario is few special characters are allowed/not allowed for input field. Its working with few browsers only but it should work for all browsers. Problem is key codes are differ from browser to browser so we need to know all key codes for all browsers. According to browser we can get key code list from online but some times those may not help us(incorrect info). In such cases we can use our own logic to know key codes. Below mentioned code can help us to full fill our requirement.
<!--
<html>
<head>
<title>Its Title</title>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" language="javascript">
function GetKeyCode(evt)
{
alert("You pressed : " + evt.keyCode);
}
</script>
</head>
<body>
Finding Key Code
<form>
Enter E-mail id: <input type="text" maxlength="46" id="email" size="50" onkeyup = "GetKeyCode(event)"/> <br/>
<input id="btnSubmit" type="button" value="Submit"/>
<input id="btnClear" type="button" value="Clear"/>
</form>
</body>
</html>
-->
<!--
<html>
<head>
<title>Its Title</title>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" language="javascript">
function GetKeyCode(evt)
{
alert("You pressed : " + evt.keyCode);
}
</script>
</head>
<body>
Finding Key Code
<form>
Enter E-mail id: <input type="text" maxlength="46" id="email" size="50" onkeyup = "GetKeyCode(event)"/> <br/>
<input id="btnSubmit" type="button" value="Submit"/>
<input id="btnClear" type="button" value="Clear"/>
</form>
</body>
</html>
-->
No comments:
Post a Comment