I have Mozilla Firefox 4.0 Beta 12
I have written a small javascript to detect ' and avoid it from getting typed in textbox. This works in IE but not on mozilla. Any suggestion ??? If that is not possible then any other logic to achieve same results ??

function DetectIllegalKeys() 
	        var code = event.keyCode;
	        if (code == 222) 
		        event.returnValue = false;
6 Years
Discussion Span
Last Post by Shantanu88d

woahh !! Dont knw JQuery !! Although my friend was telling me it's importance. Looks like it's time to learn. Btw, still isn't there neway javascript can do that ?? :|


event.keyCode does not work on mozilla. for mozilla, event.which has to be used and event has to be passed as argument

onkeydown = "return checkThis(event)
function checkThis(event)
   var code = event.which;
   alert("This works! The code is "+code);

just a small comment. It is not Firefox that is the odd man out here but IE that is the exception. I found this code at w3schools and as you can see, IE is the exception and every single other browser is the default :)

<script type="text/javascript">
function noNumbers(e)
var keynum
var keychar
var numcheck

if(window.event) // IE
keynum = e.keyCode
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)

<input type="text" onkeydown="return noNumbers(event)" />

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.