Javascript for Netscape onKeyPress

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • senthilkumarmca
    New Member
    • Feb 2006
    • 4

    Javascript for Netscape onKeyPress

    hai !

    I have one textbox which accepts only alphanumeric values. How to restrict the textbox to allow only alphanumeric values in keypress event. It works well in IE. But it wont work in netscape 8.1. pl provide script.

    Thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You should have posted your script code so we could have pointed out the problem more easily.

    However I am going to take a guess that your code doesn't check to see which browser it is running on. The problem is that the event object is not standard across browsers and the way to access the key being pressed is different, look at this example and see if it helps

    [html]
    <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.fromChar Code(keynum)
    numcheck = /\d/
    return !numcheck.test( keychar)
    }
    </script>

    <form>
    <input type="text" onkeypress="ret urn noNumbers(event )" />
    </form>

    </html>
    [/html]

    This example comes from http://www.w3schools.com/jsref/jsref_onkeypress.asp

    Comment

    • senthilkumarmca
      New Member
      • Feb 2006
      • 4

      #3
      Javascript

      hi It works fine for only one condition ie accepts number or aplphabets.

      But it wont accept alphanumeics. I had found the code for accepting alphanumeric values only.

      thanks for ur code.

      Bye

      Comment

      Working...