theworldismine
Registered
Здравейте!
Първо искам да уточня, че пускам темата в този раздел, защото всъщност проблема обхваща БД, въпреки че става дума за JS-код.
Имам следния проблем: в долупосочения скрипт има функцията за динамично добавяне на нов ред в триколонна таблица.
Проблема ми е, че не знам по какъв начин ( чрез id или name и как) да мога да изведа стойностите, които биха били въведени + и в добавените редове, за да може да се импортират от форма към база - данни.
Кода за динамичната таблица е следния:
Благодаря предварително!
Поздрави!
Първо искам да уточня, че пускам темата в този раздел, защото всъщност проблема обхваща БД, въпреки че става дума за JS-код.
Имам следния проблем: в долупосочения скрипт има функцията за динамично добавяне на нов ред в триколонна таблица.
Проблема ми е, че не знам по какъв начин ( чрез id или name и как) да мога да изведа стойностите, които биха били въведени + и в добавените редове, за да може да се импортират от форма към база - данни.
Кода за динамичната таблица е следния:
Код:
<head>
<title>Sample code - Traversing an HTML Table with JavaScript and DOM
Interfaces</title>
<script type="text/javascript" language="JavaScript"
src="rvtable.js"></script>
<script type="text/javascript">
var dynTable;
function start() {
dynTable = createDynTable(1,3);
}
function callInsertRowLast() {
insRowLast(dynTable);
}
function reload() {
window.location.reload();
}
</script>
</head>
<body onload="start()">
<input type="button" name="insertRow" value="Добави"
onClick="javascript:callInsertRowLast()"/>
<input type="button" name="deleteRow" value="Изтрий"
onClick="javascript:deleteRow(dynTable)"/>
<input type="button" name="reload" value="Презареди таблицата"
onClick="javascript:reload()"/>
<script>
// All the js requires validation.
// This function creates table dynamically,.
function createDynTable(row, col) {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
mytable = document.createElement("table");
mytablebody = document.createElement("tbody");
// creating all cells
for(var j = 0; j < row; j++) {
// creates a <tr> element
mycurrent_row = document.createElement("tr");
for(var i = 0; i < col; i++) {
// creates a <td> element
mycurrent_cell = document.createElement("td");
// add edit cell;
mycurrent_cell.onclick = function (evt) { editCell(this);};
// creates a text node
currenttext = document.createTextNode("ВЪВЕДИ" +j+", СТОЙНОСТ" +i);
// appends the text node we created into the cell <td>
mycurrent_cell.appendChild(currenttext);
// appends the cell <td> into the row <tr>
mycurrent_row.appendChild(mycurrent_cell);
}
// appends the row <tr> into <tbody>
mytablebody.appendChild(mycurrent_row);
}
// appends <tbody> into <table>
mytable.appendChild(mytablebody);
// appends <table> into <body>
mybody.appendChild(mytable);
// sets the border attribute of mytable to 2;
mytable.setAttribute("border", "2");
return mytable;
}
// Insert row into table.
function insRowLast(table)
{
alert(table.rows);
// noOfRpws in table.
noOfRows = table.rows.length;
// no of columns of last row.
noOfCols = table.rows[noOfRows-1].cells.length;
// insert row at last.
var x=table.insertRow(noOfRows);
// insert cells in row.
for (var j = 0; j < noOfCols; j++) {
newCell = x.insertCell(j);
// make cell editable feature.
newCell.onclick = function (evt) { editCell(this);};
// VALUE IN NEW CELL.
newCell.innerHTML="" + j;
}
}
//delete row
function deleteRow(table, row)
{
table.deleteRow(row);
}
//delete last row.
function deleteRow(table)
{
noOfRows = table.rows.length;
table.deleteRow(noOfRows-1);
}
//Example : In html file.
//<TD ONdblCLICK="editCell(this);">Data< /TD>
//added ONBLUR, cuz without that, u would recive an error if u had not
// edited the value in the input box
function editCell (cell) {
if (document.all) {
cell.innerHTML =
'<INPUT ' +
' ID="editCell"' +
' ONCLICK="event.cancelBubble = true;"' +
' ONCHANGE="setCell(this.parentElement, this.value)" ' +
' ONBLUR="setCell(this.parentElement, this.value)" ' +
' VALUE="' + cell.innerText + '"' +
' SIZE="' + cell.innerText.length + '"' +
'>';
document.all.editCell.focus();
document.all.editCell.select();
}
else if (document.getElementById) {
cell.normalize();
var input = document.createElement('INPUT');
input.setAttribute('value', cell.firstChild.nodeValue);
input.setAttribute('size', cell.firstChild.nodeValue.length);
input.onchange = function (evt) { setCell(this.parentNode,
this.value); };
input.onclick = function (evt) {
evt.cancelBubble = true;
if (evt.stopPropagation)
evt.stopPropagation();
};
cell.replaceChild(input, cell.firstChild);
input.focus();
input.select();
}
}
function setCell (cell, value) {
if (document.all)
cell.innerText = value;
else if (document.getElementById)
cell.replaceChild(document.createTextNode(value), cell.firstChild);
}
</script>
</body>
</html>
Благодаря предварително!
Поздрави!