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>
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?
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.......
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With