refer to the thing that had been discussed earlier, before this, there were only 5 textfields in 1 row...so, each time i would like to add, i just add and there was no problem with that..but as requirements increased, there should be 10 textfields per row..so to put all 10 textfields in 1 row, it looked something not well-arranged because I put it in the table that the size already being set. so what i was thinking right now is by making it into 2 rows by 5 each...i dunno how to modify the code so that, each time i hit ADD button, then 2 rows with 5 empty textfields per each appeared...as well as the title for each text field so that it become user friendly...
this is the code:
- Code: Select all
<script language="JavaScript">
function addRowToTable()
{
var tbl = document.getElementById('brg');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cellLeft = row.insertCell(0);
cellLeft.align='center';
row.bgColor = '#F7F5B9';
var elD = document.createElement('input');
elD.setAttribute('type', 'text');
elD.setAttribute('id', 'namabrg');
//elD.setAttribute('name', 'namabrg' + iteration);
elD.setAttribute('name', 'namabrg[]');
elD.setAttribute('size', '27');
cellLeft.appendChild(elD);
var cellLeft = row.insertCell(1);
cellLeft.align='center';
row.bgColor = '#F7F5B9';
var elD = document.createElement('input');
elD.setAttribute('type', 'text');
elD.setAttribute('id', 'kuantiti');
//elD.setAttribute('name', 'kuantiti' + iteration);
elD.setAttribute('name', 'kuantiti[]');
elD.setAttribute('size', '10');
cellLeft.appendChild(elD);
var cellLeft = row.insertCell(2);
cellLeft.align='center';
row.bgColor = '#F7F5B9';
var elD = document.createElement('input');
elD.setAttribute('type', 'text');
elD.setAttribute('id', 'nilai');
//elD.setAttribute('name', 'nilai' + iteration);
elD.setAttribute('name', 'nilai[]');
elD.setAttribute('size', '10');
cellLeft.appendChild(elD);
var cellLeft = row.insertCell(3);
cellLeft.align='center';
row.bgColor = '#F7F5B9';
var elD = document.createElement('input');
elD.setAttribute('type', 'text');
elD.setAttribute('id', 'dutiImport');
//elD.setAttribute('name', 'dutiImport' + iteration);
elD.setAttribute('name', 'dutiImport[]');
elD.setAttribute('size', '10');
cellLeft.appendChild(elD);
var cellLeft = row.insertCell(4);
cellLeft.align='center';
row.bgColor = '#F7F5B9';
var elD = document.createElement('input');
elD.setAttribute('type', 'text');
elD.setAttribute('id', 'cukaiJualan');
elD.setAttribute('name', 'cukaiJualan' + iteration);
elD.setAttribute('name', 'cukaiJualan[]');
elD.setAttribute('size', '10');
cellLeft.appendChild(elD);
}
function removeRowFromTable()
{
var tbl = document.getElementById('brg');
var lastRow = tbl.rows.length;
var iteration = lastRow;
if (iteration > 0) {
if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}
}
</script>