Quote:
Originally Posted by planoie
The blur event is separate from mouse click or key press events, so that's why you won't see a useful value for keyCode or button on the event object in an onBlur handler.
Based on your criteria, I'm not sure how you're going to filter out the conditions you don't want. You might be able to capture the keyDown event to detect the tab key (save to some global var), then in the blur event handler you can test for the last key being the tab. But if you want to filter out programmatic focus changes, you'll probably need to program that in to all the places that might move focus away from that control in order to set a flag that it was a programmatic move versus a user action.
|
So basically my four text boxes would each call the same function onBlur, but each would pass a different parameter.
Like this:
Code:
<input type="text" onBlur="blurHandler(1)"></input>
<input type="text" onBlur="blurHandler(2)"></input>
<input type="text" onBlur="blurHandler(3)"></input>
<input type="text" onBlur="blurHandler(4)"></input>
So what I decided to do is to make a proxy function for onBlur, and just have it save the parameter value that was passed. Then the mouseeventhandler checks to see if that saved value is null, and if its not, run the original blur event handler, passing it that param. Then it sets the saved value back to null.
Code:
<script>
var buttonNumberProxyValue;
function blurHandlerProxy(buttonNumber)
{
buttonNumberProxyValue = buttonNumber;
}
function blurHandler(buttonNumber)
{
//do something
}
function mousedownhandler()
{
if (buttonNumberProxyValue != null)
{
blurHandler(buttonNumberProxyValue);
}
buttonNumberProxyValue = null;
}
</script>
<body onmousedown="mousedownhandler()">
<input type="text" onBlur="blurHandler(1)"></input>
<input type="text" onBlur="blurHandler(2)"></input>
<input type="text" onBlur="blurHandler(3)"></input>
<input type="text" onBlur="blurHandler(4)"></input>
</body>