tags:

views:

93

answers:

2

Hi,

I want to capture Tab and Shift-Tab in the onblur event of a dropdownlist in javascript. Is it possible?

Help Please

thanks,

Kishore

A: 

For what purpose? I'm not sure if there's a better way to do it but you could have a couple of global boolean variables for Tab and Shift. Add keydown and keyup methods to toggle the booleans accordingly. Then during the Blur you can just do a logical check on the two.

Aaron Hathaway
i want to transfer the focus to other desired controls depending on some conditions on onblur event of a dropdown.I want to transfer the focus using onblur for which i need to capture the tab and shift-tab keyevents.
kishore
$(document).keydown(function() { //if shift key, set bool //if tab key, set bool});$(document).keyup(function() { //Check to see if either shift or tab, if so release them});$('#dropdown').blur(function() { //Check bools //If tab, do stuff //If shift+tab, do stuff});
Aaron Hathaway
Hi Aaron..thanks for the help...it worked :),but i have a small problem.I am transferring the focus to another control based on the onblur and keydown events of a dropdown,when the focus is transferred to the other control,the onblur event of that control is also executed which i dont want to ..... HOW to do this??
kishore
You can add an additional boolean. If you switch to a control from another one you can first set the boolean to true. Inside of the new control, surround everything with a check on the boolean to see how you got into it. Don't forget to reset the value at the end of the block.
Aaron Hathaway
A: 

onblur is not enough... You need to capture KeyEvents and check and store if tab/shift-tab are pressed. Then you can check for those keys in the blur-handler.

hacksteak25
when i use both the onblur and keyeventhandlers the onblur is getting fired and the keyevents are not getting fired...any idea???
kishore
Are there any events fired when you press a key? To trigger an onblur by shortcuts like tab or shift-tab, the onkeydown-event must be fired before.
hacksteak25
oh okay thanks hacksteak25,,,i used both the onblur and key events and its working :)
kishore