Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:20:46+00:00 2026-05-22T03:20:46+00:00

To learn JavaScript I am writing a small text editor Google Chrome extension. But

  • 0

To learn JavaScript I am writing a small text editor Google Chrome extension. But I keep getting this error: Cannot read property 'value' of undefined. It happens whenever tranquility.save(); is called, but not when tranquility.open(); which is weird because they are basically the same, just switched the sides. paper is just a <textarea>.

var tranquility = {
 paper: document.getElementById("paper"),
 lastOpenedPaper: localStorage.getItem("lastOpenedPaper"),

 listen: function() {
    this.paper.addEventListener("keyup", this.save, false);
 },

 save: function() {
    localStorage.setItem(this.lastOpenedPaper, this.paper.value);
 },

 open: function() {
    this.paper.value = localStorage.getItem(this.lastOpenedPaper);
 }
}

EDIT:

It is called after <textarea> is created (unless it has to be the entire DOM)

<body>
    <textarea id="paper"></textarea>
    <script src="../js/application.js"></script>
    <script>
        tranquility.listen();
    </script>
</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:20:46+00:00Added an answer on May 22, 2026 at 3:20 am

    I got it working with two fixes

    1.) Write the script after loading of paper textarea. It was done by placing script at the end of body.

    2.) I found localStorage.setItem and localStorage.getItem should refer to the variable name like in http://hacks.mozilla.org/2009/06/localstorage/ . In your code lastOpenedPaper would refer to null value in begining so it won’t store value in that name so i tried replacing it with just. you can use other var name too or use varname directly as localStorage.setItem('anyvarname', this.paper.value);

    code:

    <script>
        var tranquility = {
         paper: document.getElementById("paper"),
         lastOpenedPaper: 'just',
    
         listen: function() {
            this.paper.addEventListener("keyup", this.save, false);
         },
    
         save: function() {
            localStorage.setItem(this.lastOpenedPaper, this.value);
         },
    
         open: function() {
            this.paper.value = localStorage.getItem(this.lastOpenedPaper);
         }
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn JavaScript by writing a Google Chrome extension for Reddit so
I've never learnt JavaScript, but I imagine this is quite a simple problem. Just
I haven't started writing any code for this program, but here's what I need
This may sound impossible but read on. I need to learn jQuery a little
I'm trying to learn Javascript closures. I'm having trouble getting my head around the
In my quest to learn javascript (which seems to be my latest source of
I am just starting to learn javascript, so I don't have the skills to
What are some good resources to learn best practices for Javascript? I'm mainly concerned
I have some javascript that I'm trying to retool using jQuery to learn the
I'm trying to learn jQuery, to make up for my anemic javascript skills. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.