This simple program displays the Keycode & event type for a key pressed. Good for a quick reference.
<html> <head> <title>Keyboard Events and Codes</title> <style type="text/css"> body {font-family:Arial, sans-serif} h1 {text-align:right} td {text-align:center} </style> <script language="JavaScript" type="text/javascript"> // array of table cell ids var tCells = ["downKey", "pressKey", "upKey", "downChar", "pressChar", "upChar", "keyTarget", "character"];
// clear table cells for each key down event function clearCells() { for (var i = 0; i < tCells.length; i++) { document.getElementById(tCells[i]).innerHTML = "—"; } }
// display target node's node name function showTarget(evt) { var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if (node) { document.getElementById("keyTarget").innerHTML = node.nodeName; } }
// decipher key down codes function showDown(evt) { clearCells(); evt = (evt) ? evt : ((event) ? event : null); if (evt) { document.getElementById("downKey").innerHTML = evt.keyCode; if (evt.charCode) { document.getElementById("downChar").innerHTML = evt.charCode; } showTarget(evt); } }
// decipher key press codes function showPress(evt) { evt = (evt) ? evt : ((event) ? event : null); if (evt) { document.getElementById("pressKey").innerHTML = evt.keyCode; if (evt.charCode) { document.getElementById("pressChar").innerHTML = evt.charCode; } showTarget(evt); var charCode = (evt.charCode) ? evt.charCode : evt.keyCode; // use String method to convert back to character document.getElementById("character").innerHTML = String.fromCharCode(charCode); } }
// decipher key up codes function showUp(evt) { evt = (evt) ? evt : ((event) ? event : null); if (evt) { document.getElementById("upKey").innerHTML = evt.keyCode; if (evt.charCode) { document.getElementById("upChar").innerHTML = evt.charCode; } showTarget(evt); } }
// set page-wide event listeners document.onkeydown = showDown; document.onkeypress = showPress; document.onkeyup = showUp; </script> </head> <body> <h1>Key and Character Codes vs. Event Types</h1> <hr> <p>Enter some text with uppercase and lowercase letters:<br> <form> <input type="text" id="entry" size="60" onkeydown="showDown(event)" onkeypress="showPress(event)" onkeyup="showUp(event)"> </textarea></p> </form> <table border="2" cellpadding="5" cellspacing="5"> <caption>Keyboard Event Properties</caption> <tr><th>Data</th><th>keydown</th><th>keypress</th><th>keyup</th></tr> <tr><td>keyCode</td> <td id="downKey">—</td> <td id="pressKey">—</td> <td id="upKey">—</td> </tr> <tr><td>charCode</td> <td id="downChar">—</td> <td id="pressChar">—</td> <td id="upChar">—</td> </tr> <tr><td>Target</td> <td id="keyTarget" colspan="3">—</td> </tr> <tr><td>Character</td> <td id="character" colspan="3">—</td> </tr> </table> </body> </html>
The event which in the following keydown function code is not returning the correct key codes. I have checked this in Chrome using the developer tools and the console.log(e.which) statement in my code.
The .find() method does not seem to match on input fields by using a class. The ti This problem seems to be only visible on input fields. The following is a demonstration of the issue:
The site I'm working on uses a CMS (which I have no access to, nor control over the output), and in one section of the site, it outputs divs like this (I've changed the actual ID names for clarity's sake)...
Now then, I need to be able to check if a div is called 'generated-div-[number]', and I thought the best way to go about this would be to use regex. However, most of my regex experience comes from doing PHP work.
So far, I've got this...
That's a slightly simpler version of what I want it to do (i.e: in the end, I don't want to merely change the BG colour), but I mainly need some help with the regex and 'if' part of things.
I have an array of integersI like to retrieve the max number and index of max number from that array without using Math.Max() function..Presently in this below code, I have 4 dynamic values, end user will be select degree from combo box, entering the values semester, Max marks and Obtained marks as numeric values. Once entered dynamic rows will be created and it also calculate the percentage by the formula (om/mm)*100 for each row on clicking Sum and it also creates new columnŠI needed to have code when the degree changes only.. it should calculate the sum of all max.marks and Obtained marks of each semester and then calculate percentage by above formulaŠ and also new column should not be createdsort with max markswhat is the easiest way...
I have this js function for pulling out a couple of links which I want to add onclick handlers to... but IE can't find the rel attribute the way Im doing it, Im assuming it can another way, but I dont know how?!this works in Chrome, but not IE... the category_links.length yields a fat 0.
function get_product_categories_links(){ var links = document.getElementsByTagName('a'); var category_links = [];
I have around 100 item details in a page...i want to show it only 18 item details on page load. and the remaining items needs to be displayed only when user scrolls down the page to end. how to find out below fold in javascript?
I am looking for a counter that starts at 0 when the page is loaded and counts in increments of a certain number, for example "100" every second. So it would display 100, then 200, then 300, etc.
how to find the coodinates for a picture in a middle of the page for example with js? I need this because i have a js script that get the mouse coodinates (X,Y) for the page.I have to modify this script to work only at my picture area and to get me the coordinates for my picture not the coordinates for my hole page. Code:
Does anyone know if it is possible to find out what element in the DOM made a call? Let's say I have a table and every cell has an onClick event attached to it. Is there a way to figure out what particular cell was clicked in the DOM? I know it would be easy to use ID's and just do an getElementById(), but, the ID's are generated from the system and I can't ever be sure what number any particular cell is, so I need another way if possible.
Can someone help to find the filesize ?? i have got the path of the file c:pritime.jpg and now i want to get teh filesize of this can someone tell me how can i do this???
how can i use the .indexof function to check if there is a quote in the string. i can't seem to find the correct syntax for do this without an error occuring
I would like to include a 'back to page' link on my website. This link should load the target page when it's not currently open and set focus to the window if it is.
in pseudo code
win = FindWindow("Products.htm"); if (win ==0) open("Products.htm"); else win.focus();