I am trying to make a list navigable using the up/down arrow keys - which worked but pressing these keys causes the window to scroll which is very annoying. So I want to disable to movement of the page using the arrow keys when this box is focused.
I tried:
$('.selectionList').focus(function(event){
$(document).keydown(function(e) {
return false;
});
});
$('.selectionList').blur(function(event){
$(document).keydown(function(e) {
return true;
});
});
But the re-enabling of these keys did not work to the page wouldn't scroll without the scrollbar. I found this which I could use but this would disable the use of these keys permanently, which I do not want to happen.
The $('.selectionList').keyup() event is as follows:
$('.selectionList').keyup(function(event){
if (event.keyCode == 13) //enter
{
$('.listNameBox a').click();
}
else
{
if ((event.keyCode == 38) && ($(this).children('li:eq(' + ($('.selectionList li.selected').index() - 1) + ')').length > 0)) //up
{
selectListItem($(this).children('li:eq(' + ($('.selectionList li.selected').index() - 1) + ')'));
}
else if ((event.keyCode == 40) && ($(this).children('li:eq(' + ($('.selectionList li.selected').index() + 1) + ')').length > 0)) //down
{
selectListItem($(this).children('li:eq(' + ($('.selectionList li.selected').index() + 1) + ')'));
};
}
});
Any help would be appreciated.