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;
	        }
          }

Recommended Answers

All 7 Replies

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 ?? :|

ya, but jquery just makes the who browser compatibility thing much easier.

cool...will try that out

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

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 :)

<html>
<body>
<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)
}
</script>

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

</body>
</html>

Ohh, so that is so !! Thanks for the info !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.