McNavy McNavy - 1 year ago 64
HTML Question

Detect "Entry key" press for custom function

I want detect when user use Entry. I want this, because I want custom the action made by the key. The key will be add a new row on my table. Can you add me please?



This solution work but I search now, for add a new line for my table when user press Entry key :

<script type="text/javascript">
function stopEntryKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = ( ? : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type == "text")) {
return false;
$("tbody").html("<tr><td>Item1-col1</td><td>Item1-col2</td></tr>"); // Ajoute une ligne
document.onkeypress = stopEnterKey;

But this line : $("tbody").html("Item1-col1Item1-col2");` // Ajoute une ligne don't add one row for my table.

Answer Source

Let's say the HTML is as follow



Now the JS:

$(document).keydown(function() {   
   if (event.keyCode == '13') {
       $("tbody").html("<tr><td>Item1-col1</td><td>Item1-col2</td></tr>";  //this 'll add row in the table
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download