Click to See Complete Forum and Search --> : Question about tables
curioususer
07-22-2003, 08:54 AM
Ok here's my problem...I have a table on a page of mine that pulls information from a SQL database and I needed to be able to edit the information then save it...well a few of the fields I can edit using select boxes so i wrote functions and onclick events to edit those fields and some SQL stuff to save them. Now I need for one of the cells to turn into a text box with the value that was there in it and it be able to be changed into what they want then for it to save...you are probably going to need the code so if anyone has any ideas just tell me and ill post it. Thanks a million.
Gollum
07-22-2003, 09:09 AM
Here's a simple example you can play with...
<html>
<head>
<script>
function input_onblur()
{
this.parentNode.inEdit = false;
this.parentNode.innerHTML = this.value;
}
function EditCell(oTD)
{
if ( oTD.inEdit ) return;
oTD.inEdit = true;
var value = oTD.innerHTML;
oTD.innerHTML = "<input type=text value='" + value + "'>";
oTD.firstChild.onblur = input_onblur;
oTD.firstChild.focus();
}
</script>
</head>
<body>
<table>
<tr>
<td onclick="EditCell(this);">123</td>
<td onclick="EditCell(this);">456</td>
<td onclick="EditCell(this);">789</td>
</tr>
<tr>
<td onclick="EditCell(this);">abc</td>
<td onclick="EditCell(this);">def</td>
<td onclick="EditCell(this);">ghi</td>
</tr>
<tr>
<td onclick="EditCell(this);">Tom</td>
<td onclick="EditCell(this);">Dick</td>
<td onclick="EditCell(this);">Harry</td>
</tr>
</body>
</html>