/    Sign up×
Community /Pin to ProfileBookmark

‘Esc’ key logic … how do you test?

In the following test of a concept (do nothing) script:

Clicking on the checkbox displays the table.
Clicking on a table value, changes the textbox and hides the table.

I want to be able to hide the table again without changing the text box contents by pressing the ‘escape’ key.

Is there a way to do this?

[code]
<html>
<head>
<title>Escape logic</title>
<script type=”text/javascript”>
function Show(msg) {
document.getElementById(‘_info’).style.display = ‘none’;
document.getElementById(‘ckBox’).checked = false;

// Looking for test here to NOT write to textbox if ‘Escape’ has been pressed
// if (??? != ESC) {
document.getElementById(‘info’).value = msg;
// }
}
</script>
</head>
<body>
<input type=”text” id=”info” value=”Something Brilliant!”>
<input type=”checkbox” id=”ckBox”
onclick=”if(this.checked==true){document.getElementById(‘_info’).style.display=’block’}”>
<span id=”_info” style=”display:none”>
<table border=”1″><tr>
<td><span onclick=”Show(‘Home’)”>Home</span></td>
<td><span onclick=”Show(‘Up’)”>Up</span></td>
<td><span onclick=”Show(‘PgUp’)”>PgUp</span></td>
</tr><tr>
<td><span onclick=”Show(‘Prev’)”>Prev</span></td>
<td><span onclick=”Show(‘Now’)”>Now</span></td>
<td><span onclick=”Show(‘Next’)”>Next</span></td>
</tr><tr>
<td><span onclick=”Show(‘End’)”>End</span></td>
<td><span onclick=”Show(‘Down’)”>Down</span></td>
<td><span onclick=”Show(‘PgDn’)”>PgDn</span></td>
</tr></table>
</span>
</body>
</html>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameMay 31.2009 — Set an onkeydown event on the document and watch for keyCode 27:

[CODE]<script type="text/javascript">

document.onkeydown = function (evt) {
var e = evt || window.event;
alert(e.keyCode);
if (e.keyCode == 27) {
Show('',true);
}
}
function Show(msg,bypass) {
document.getElementById('_info').style.display = 'none';
document.getElementById('ckBox').checked = false;
if (!bypass) {
document.getElementById('info').value = msg;
}
}
</script>[/CODE]

More info on keyCodes:

http://www.quirksmode.org/js/keys.html
Copy linkTweet thisAlerts:
@JMRKERauthorMay 31.2009 — Thank you 'astupidname', I'll give that a try.

?
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...