javascript working in IE bt not in other browsers

Posted by Santosh198318 under JavaScript on 11/17/2010 | Points: 10 | Views : 1356 | Status : [Member] | Replies : 3
Hi this is santosh.....

Below mentioned code is working in IE but not in other browsers(mozilla,chrome) please provide some related information to how to solve this issue
function isCharacterKey ()
{
//var keyCode =0; //window.event.keyCode;

if ( event.keyCode>=48 && event.keyCode <=57)
{

alert("enter only characters");
return false;

}
else
{

return true;

}

}




Responses

Posted by: Lalji_mer on: 11/17/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

For information check this link might be help!

http://balanagaraj.wordpress.com/2008/05/07/javascript-differences-in-mozilla-firefox-and-internet-explorer/

LP MER

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/17/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Santhosh,

Refer the link...

http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html

Know about Keyboard Event in all Browsers...

http://unixpapa.com/js/key.html

Cheers :)

Thanks,
T.Saravanan

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 11/17/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
In order to avoid these kinds of error, it is suggested to user jQuery that is most browser compatible and easy to use.

Use following to get keycode in jQuery (just copy paste and try to type something in the textbox).

    <input type="text" id="txt1" />


<script language="javascript" type="text/javascript">
$("#txt1").keypress(function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
alert(code);
});
</script>


Hope this will help.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response