I can't prevent key presses from changing a selected option in Firefox

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-02-11T15:02:36Z Indexed on 2010/06/08 23:02 UTC
Read the original article Hit count: 235

Filed under:
|
|

Using Firefox 3.5.7

The following test page should behave like Opera, Safari and Chrome.

Key presses (arrows or 1-5) should have no effect (i.e. The events should be cancelled so that the number never changes from the initial default "3").

[I have separate working code for IE too].

Many thanks to anyone who can make it work?

<html>  
    <head> 
        <title>Test</title>  
        <script type='text/JavaScript'>  
            function stop(evt)  
                {evt.preventDefault();  
                 evt.stopPropagation();  
                };  
        </script>  
    </head>  
    <body>  
        <select onkeydown='stop(event);' onkeypress='stop(event);'>  
            <option>1</option>  
            <option>2</option>  
            <option selected="selected">3</option>  
            <option>4</option>  
            <option>5</option>  
        </select>  
    </body>  
</html> 

© Stack Overflow or respective owner

Related posts about firefox

Related posts about select