I'm trying to set a textarea value from localStorage in a handlebars template but have had no luck. The code works fine as soon as I take it out fo the template tags, but within it does nothing. From what I've read setting on document ready should work, but for me it's not.
I'm trying to store the comment whilst the user goes away and logs in or registers.
Here's the code I have:
$(document).ready(function () {
if (localStorage['comment_text']) {
var user_comment_text = localStorage['comment_text'];
$('textarea#comment_text').val(user_comment_text);
}
});
Am I doing something stupid here?
Edit
When logged to console it is getting the value from localStorage. Just doesn't set it in the textarea. I'm guessing it's to do with the 'textarea#comment_text' not being available when the javascript is being executed. I thought calling on document ready would solve this.