Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preventDefault() not working on SELECT elements in Firefox 9.0.1

I realise there are other questions on preventDefault() not working with Firefox, but they did not help me.

I've got three SELECT lists, and all I want is to navigate between them using the arrow keys without changing any values. The code works great in Chrome, but in Firefox it moves focus and then changes the value on the element just moved to.

http://jsbin.com/ofitif/3/edit

JavaScript:

$(document).ready(function () { 
  $('.myinput').keydown(function (evt) { onkeydown(evt); });
  $('.myinput:first').focus(); 
}); 

function onkeydown(evt) {
  evt.preventDefault();
  console.log(evt.which);
  if(evt.which == 39) {
    $(document.activeElement).next().focus();
  }
  else if(evt.which == 37) {
    $(document.activeElement).prev().focus();
  }             
}

HTML:

<div id="inputs">
    <select class="myinput">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select>
    <select class="myinput">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select>
    <select class="myinput">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select>
</div>
like image 309
Ace Avatar asked Jan 15 '12 13:01

Ace


2 Answers

nsListControlFrame::KeyPress in http://mxr.mozilla.org/mozilla-central/source/layout/forms/nsListControlFrame.cpp doesn't seem to check whether the default action was prevented. File a bug?

like image 66
Boris Zbarsky Avatar answered Nov 01 '22 18:11

Boris Zbarsky


according to your requirement try passing value for prevent default..it will be something like below..

evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;

it worked for me plz try it.......

like image 36
mandava Avatar answered Nov 01 '22 18:11

mandava