Keyboard shortcuts with javascript
Posted: Sun Nov 12, 2006 12:15 pm
Is there a way to show/hide a table with a keyboard shortcut using javascript?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
adamb10 wrote:Ok. I dont really know much(if any) javascript.
Code: Select all
function readKey(e)
{
if (e.keyCode == 46) alert('Delete pressed!');
}
if (document.captureEvents) document.captureEvents(Event.KEYDOWN);
document.onkeydown = readKey;
No, let's say you wanted the "h" key to toggle the table display.adamb10 wrote:ok, and what do I put in the table tag? Readkey?
Code: Select all
function toggleTable(e)
{
e = e || window.event;
if (e.keyCode == 72) //Key code for h
{
var tableElement = document.getElementById('my_table');
if (tableElement.style.display == 'block') tableElement.style.display = 'none';
else tableElement.style.display = 'block';
}
}
if (document.captureEvents) document.captureEvents(Event.KEYDOWN);
document.onkeydown = toggleTable;Code: Select all
<table id="my_table" ... >Code: Select all
function toggleTable(e)
{
e = e || window.event;
if (e.keyCode == 72) //Key code for h
{
var tableElement = document.getElementById('my_table');
if (tableElement.style.display == '') tableElement.style.display = 'none';
else tableElement.style.display = '';
}
}
if (document.captureEvents) document.captureEvents(Event.KEYDOWN);
document.onkeydown = toggleTable;