I am working on a project with multiple textareas that will be editable to others.
I have started using localstorage to allow the inputted contents to be saved on the browser.
This works fine, but I can only get it to work on one text area in the document. I know this means I will need to duplicate and rename some aspect of the JS code, but I am at a loss after trying several different ways. I figure I'd ask the pros.
The HTML (some of it anyway)
<div id="columns">
<ul id="column1" class="column">
<li class="widget color-red" id="edit1" contenteditable="true">
<div class="widget-head">
<h3>Widget title</h3>
</div>
<div class="widget-content">
<textarea class="outer" id="persisted-text" rows=5 cols=30></textarea>
</div>
</li>
<li class="widget color-red">
<div class="widget-head">
<h3>Widget title</h3>
</div>
<div class="widget-content">
<textarea class="outer" rows=5 cols=30></textarea>
</div>
</li>
</ul>
and the JS/Jquery:
var supported = 'This text will be saved locally, forever.',
unsupported = 'Oh no! Your browser does not support localStorage.';
if (window.localStorage) {
var p = document.querySelector('#persisted-text');
if (localStorage.text == null) {
localStorage.text = p.value = supported;
} else {
p.value = localStorage.text;
}
p.addEventListener('keyup', function(){ localStorage.text = p.value; }, false);
} else {
document.getElementById('persisted-text').value = unsupported;
}
The trigger of id="persisted-text" works fine with the first text area, but does not do anything to the others. What portion of this code would I need to change/add to to start adding multiple localstorage textareas? Also, a jsfiddle if it helps: http://jsfiddle.net/6LdfD/6/ Thanks!