views:

30

answers:

2

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

This works for me (looks pretty evil, I haven't found any other solution on FF so far):

<html>  
<head> 
    <title>Test</title>  
    <script type='text/JavaScript'>
        function stop(evt) {
          evt.preventDefault();
          var elem = document.getElementById('mysel');
          elem.blur();
          setTimeout('refocus()', 0);
        };
        function refocus() {
          document.getElementById('mysel').focus();
        }
    </script>  
</head>  
<body>  
    <select id="mysel" onkeydown="stop(event);">  
        <option>1</option>  
        <option>2</option>  
        <option selected="selected">3</option>  
        <option>4</option>  
        <option>5</option>  
    </select>  
</body>  

boxofrats
A: 

@icktofay: This is a simplified test page demonstrating the problem. What I am actually doing in the main code is replacing the select-box's intrinsic keystroke handling with explicit actions.

@boxofrats: Yes, that is evil... but effective. Thanks.

Anthony