Forum Moderators: open

Message Too Old, No Replies

contenteditable attribute problem

contenteditable

         

Al_Fla

2:28 am on Oct 10, 2020 (gmt 0)

5+ Year Member



Hi - I hope I'm posting this to the proper forum.

I found a really simple script to use for the “contenteditable” attribute. Before I added other HTML and tags on the page, I just wanted to test it. I tried it and the "save my edits" button doesn't work. I just copied and pasted their demo source code, so it should work.

Below is the code -
Any help would be greatly appreciated!
-----------

<!DOCTYPE html>
<html>
<head>
<title>Developer Drive | Allowing Users to Edit Text Content with HTML5 | Demo</title>
<script type="text/javascript">
function saveEdits() {

//get the editable element
var editElem = document.getElementById("edit");

//get the edited element content
var userVersion = editElem.innerHTML;

//save the content to local storage
localStorage.userEdits = userVersion;

//write a confirmation to the user
document.getElementById("update").innerHTML="Edits saved!";

}
function checkEdits() {

//find out if the user has previously saved edits
if(localStorage.userEdits!=null)
document.getElementById("edit").innerHTML=localStorage.userEdits;
}
</script>
</head>
<body onload="checkEdits()">
<p>This is a demo to accompany the following tutorial: <a href="http://www.example.com/2012/06/allowing-users-to-edit-text-content-with-html5">Allowing Users to Edit Text Content with HTML5</a></p>
<hr />
<div id="edit" contenteditable="true">Here is the element's original content</div>
<p><input type="button" value="save my edits" /></p>
<div id="update">Edit the text and click to save for next time</div>
</body>
</html>





[edited by: not2easy at 2:36 am (utc) on Oct 10, 2020]
[edit reason] Please see ToS [webmasterworld.com] [/edit]

not2easy

2:49 am on Oct 10, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Hi Al_Fla and welcome to WebmasterWorld [webmasterworld.com]

Sorry your post needed some minor edits. That Welcome link can help explain more about how these forums work and how to access the formatting tools. The Charter explains why the edits were applied: [webmasterworld.com...]

Unlike some other sites, we don't do reviews because we prefer to educate webmasters to make their own judgements, rather than discuss specifics of any site.

Sorry, I'm not js fluent, others who can help will see your code shortly.

Al_Fla

2:59 am on Oct 10, 2020 (gmt 0)

5+ Year Member



Thanks!
I'm tired and neglected to read the welcome post until after I posted, then after I posted it again I noticed there was a link in the code.
I guess my brain is on vacation tonight!
Thanks and enjoy your weekend!

Al