I have a function that focuses the user to a form on the page (a search box). I am now needing to implement another form element on the same page. And i just realized my function isn't going to work very well on that page.
My function sends the user to the search box when the press the letter S on the keyboard. Is it possible to throw in if statement in there that first checks to see if they are already in a form element on the page. And if they are, then not do anything? Here's my current function:
_______________
_brian.
My function sends the user to the search box when the press the letter S on the keyboard. Is it possible to throw in if statement in there that first checks to see if they are already in a form element on the page. And if they are, then not do anything? Here's my current function:
Code:
function sendToSearch(e) {
e = (e) ? e : event;
var keycode = (e.keyCode) ? e.keyCode : (e.which) ? e.which : false;
character=String.fromCharCode(keycode);
if(keycode == "83" || keycode == 83 || character == "s"){
document.forms['search_box'].elements['search'].focus();
}
}
document.onkeypress = sendToSearch;
_______________
_brian.