How to cancel the select element's default event in firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muiz123
    New Member
    • Jun 2010
    • 8

    #1

    How to cancel the select element's default event in firefox

    for the select element, if use click the left arrow key, then the select index will be changed, I want to cancel this default event, how can I do?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    		<title>Untitled Document</title>
    	</head>
    	<body>
    		<select id="select" onkeypress="test(event)">
    			<option value="aaa">a</option>
    			<option value="bbb">b</option>
    			<option value="ccc">c</option>
    		</select>
    		<script type="text/javascript">
    			function test(event) {
    				event = (event || window.event);
    				var key = (event.keyCode || event.charCode);
    				if(key == 37 || key == 39) {
    					event.stopPropagation();
    					event.preventDefault();
    					return false;
    				}
    			}
    		</script>
    	</body>
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Seems to be a bug.

    Perhaps you could use a timeout with blur/focus to solve the problem?

    Comment

    • Logician
      New Member
      • Feb 2007
      • 210

      #3
      Originally posted by muiz123
      for the select element, if use click the left arrow key, then the select index will be changed, I want to cancel this default event, how can I do?

      Code:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      	<head>
      		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      		<title>Untitled Document</title>
      	</head>
      	<body>
      		<select id="select" onkeypress="test(event)">
      			<option value="aaa">a</option>
      			<option value="bbb">b</option>
      			<option value="ccc">c</option>
      		</select>
      		<script type="text/javascript">
      			function test(event) {
      				event = (event || window.event);
      				var key = (event.keyCode || event.charCode);
      				if(key == 37 || key == 39) {
      					event.stopPropagation();
      					event.preventDefault();
      					return false;
      				}
      			}
      		</script>
      	</body>
      </html>
      My guess is that they don't want you messing with default accessibility controls.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        an option to achieve the functionality then could be to avoid the use of the standard select-element and use a custom DHTML one ...

        kind regards

        Comment

        Working...