469,282 Members | 1,977 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

window.onkeydown but not for a specific div or form

I have set window.onkeydown which works fine.
One of my shortcut keys is "n", so a user can not type "n" in forms.
How do I solve that?

Thanks,
Jacob
Jul 23 '05 #1
5 4248
Jacob Friis Larsen wrote:
I have set window.onkeydown which works fine.
One of my shortcut keys is "n", so a user can not type "n" in forms.
How do I solve that?

Thanks,
Jacob


<script type="text/javascript">

document.onkeydown = function(e)
{
var tgt = null;
if ((e = e || window.event)
&& (tgt = e.target || e.srcElement)
&& tgt.type
&& /text/.test(tgt.type))
return true;
else
{

//stuff here

}
}

</script>

Jul 23 '05 #2
Could someone please explain what this does?

Thanks,
Jacob

Jul 23 '05 #3
Jacob Friis Larsen wrote:
Could someone please explain what this does?

Thanks,
Jacob
Someone here. Best I could do, based on this detailed description:
I have set window.onkeydown which works fine.


document.onkeydown = function(e)
{
var tgt = null;
if ((e = e || window.event) //get event object
&& (tgt = e.target || e.srcElement) //get trigger element
&& tgt.type //has 'type' property?
&& /text/.test(tgt.type)) //'text' or 'textarea'?
return true; //end processing
else
{

// shortcut code

}
}

</script>

Jul 23 '05 #4
Thanks alot RobB :)
Kind regards Jacob

Jul 23 '05 #5
What if a user press ' to search for a link in Firefox?
I see this as a problem for gmail too.
Can that be fixed?

Thanks, Jacob

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Brad Jones | last post: by
5 posts views Thread by Russell Campbell | last post: by
32 posts views Thread by Eli | last post: by
5 posts views Thread by Dave Henson | last post: by
3 posts views Thread by news.microsoft.com | last post: by
8 posts views Thread by Someone | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.