Forum Moderators: open
For JavaScript references...
Key Pressed // JavaScript Key Code
Tab // 9
Shift // 16
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Cancel TAB for onkeypress JavaScript Event</title>
<script type="text/javascript">
//<![CDATA[
function change(id, newClass)
{
identity=document.getElementById(id);
identity.className=newClass;
}
//]]>
</script>
<style type="text/css">
a:focus {
background: #222;
color: #fff;
}
div.prompt {
display: none;
}
div.showme {
border: #000 solid 1px;
}
</style>
</head><body>
<p>The goal of modifying this script to to make any key other then tab
<br />
<a href="#" onkeypress="if (event.keyCode == 9) return true; else change('hiddenlayer', 'showme');">anchor one (press TAB)</a>
<br />
<a href="#" onkeypress="if (event.keyCode === 16) return true; else change('hiddenlayer', 'showme');">anchor two (press SHIFT+TAB)</a>
<br />
<a href="#" onkeypress="if (event.keyCode == 9) return true; else change('hiddenlayer', 'showme');">anchor three (press TAB)</a><div class="prompt" id="hiddenlayer">A hidden layer</div>
</body>
</html>
- John