By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

window.onkeydown but not for a specific div or form

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
Could someone please explain what this does?

Thanks,
Jacob

Jul 23 '05 #3

P: n/a
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

P: n/a
Thanks alot RobB :)
Kind regards Jacob

Jul 23 '05 #5

P: n/a
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.