I am new to javascript and I want to dynamically generate lines when I press Tab and want to get enterd values ββin dynamically generated lines so that I can use these values ββin my servlet code.
Here is my html
<html> <head> <title> Add/Remove dynamic rows in HTML table </title> <script src="table.js" language="javascript" /></script> </head> <body onload="hello()"> <form action="servletname"> <input type="button" value="Delete Row" onclick="deleteRow()" /> <table id="table1" width="350px" border="2"> <tr> <td align="center"> Sr.No </td> <td align="center" style="width:50px;"> Code </td> <td align="center" style="width:1100px;"> Test Name </td> <td align="center" style="width:80px;"> Rate </td> </tr> </table> <table id="table2" width="350px" border="2"> <tr> <td><input type="checkbox" name="chk"/></td> <td> 1 </td> <td> <input type="text" id="tc" style="width:50px;" /> </td> <td> <input type="text" id="tn" style="width:190px;" /> </td> <td> <input type="text" id="rt" style="width:80px;" onkeypress="KeyCheck(event)" /> </td> </tr> </table> <br><input type="text" id="rt1" style="width:80px;"/> </form> </body> </html>
The code for the file "row.js":
function hello() { document.getElementById("tc").focus(); } function KeyCheck(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; if(KeyID==9) { addRow(); } } function addRow() { var table = document.getElementById("table2"); var rowCount = table.rows.length; var row = table.insertRow(table.rows.length); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.style.width = "50px"; cell3.appendChild(element2); var cell4 = row.insertCell(3); var element3 = document.createElement("input"); element3.type = "text"; cell4.appendChild(element3); var cell5 = row.insertCell(4); var element4= document.createElement("input"); element4.type = "text"; element4.style.width = "80px"; cell5.appendChild(element4); element4.focus();
But it does not detect Tab or any key other than Enter. Plz tell me how to detect a βTabβ or some other key in this program and how can I access the values ββentered in these lines created using a diaman.
source share