/    Sign up×
Community /Pin to ProfileBookmark

Trying to get Table cell to be editable

I have found the following script on the net, and it does exactly what I want it to do except it won’t save the info. Can anyone help. I am trying use a table in HTML and have the cell be editable online. This script works great but won’t save the changes. What am I doing wrong. I am new at this so please work with me.

Here is what I have:

<SCRIPT>
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>

<TABLE BORDER=”1″>
<TR>
<TD ONCLICK=”editCell(this);”>
jsunity
</TD>
<TD ONCLICK=”editCell(this);”>
erstaunt
</TD>
<TD ONCLICK=”editCell(this)”>
immer wieder
</TD>
</TR>
</TABLE>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 19.2005 — 
except it won't save the info.
[/quote]


Javascript is a client-side language, thus the dynamic changes are to be kept only during the sesion, so that you can not save them for a later use. For that you need either a cookie or, better, a server-side aplication.
×

Success!

Help @Jack_Price spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...