Gouse Feroz
Gouse Feroz

Reputation: 53

Creating a html page that store data dynamically

I want to create a HTML page, which when entered any text in text area, that text should be populated into the page and when closed the page and opened again, the previously entered data should be seen there. Please help me achieve this...

I dont want this with the help of PHP.

Please refer the below image for what i was trying My page what i was trying to make

Upvotes: 0

Views: 52

Answers (1)

klaasman
klaasman

Reputation: 897

You can save data on the client by using window.localStorage (or use a fallback with cookies), an example implementation could look like:

// tiny utils to save and load entered text
const saveText = (text) => localStorage.setItem('text', JSON.stringify(text))
const loadText = () => JSON.parse(localStorage.getItem('text'))

// get a reference to our `textarea` and listen for changes
document
  .querySelector('textarea')
  .addEventListener('change', evt => saveText(evt.target.value))


// somewhere else in the app, e.g. on load, you could prefill the textarea
document.querySelector('textarea').value = loadText()

Upvotes: 1

Related Questions