Forum Moderators: open
I've been googling for some time for this, but no luck so far. Guess i don't use the right words.
This is what im looking for, i hope someone here migth point me in the right direction.
Im making a invoice script, and are struggelig with the java/ajax(not my strongest side)
An invoice often contain more then one line.
Lets say my invoice should have theese lines :
# ¦ Description ¦ Price ¦
1 ¦ Newspaper ¦ 1$ ¦
1 ¦ Eggs ¦ 2 $ ¦
2 ¦ Milk ¦ 1 $ ¦
1 ¦ Newspaper ¦ 1$ ¦
1 ¦ Eggs ¦ 2 $ ¦
2 ¦ Milk ¦ 1 $ ¦
I want to have 3 lines to show by default, and if i need more lines to write in i hit a javabutton, and a new line apperers...
Hope someone can kick me in the right direction.
<html><head><title>TEST</title>
<script>
function addRow(id){
var table = document.getElementById(id);
var tbody = table.getElementsByTagName('tbody')[0];
var row = tbody.rows[tbody.rows.length-1].cloneNode(true);
/* Note that cloneNode will copy attributes.
* This is probably useful wrt names, need to clear values: */
var inputs = row.getElementsByTagName('input');
for(var k=-1, input; input=inputs[++k];)
input.value = "";
tbody.appendChild(row);
}
</script>
</head>
<body>
<table id="invoiceTable">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name="code" type="text" value=""></td>
<td><input name="desc" type="text" value=""></td>
<td><input name="pric" type="text" value=""></td>
</tr>
</tbody>
<tfoot>
<td colspan="3">
<button onclick="addRow('invoiceTable')">add row</button>
</td>
<tfoot>
</table>
</body>
</html>