2

(If something isnt wrote right, please edit, Im not SUPER good with english language) So i need save the Input’s Value in javascript, and Ive tried use .value with a selector, but it fails to return the value.

jquery function val() is not equivalent to "$(this).value="? This question had some valuable insight, but didnt answer my question.

var Value = document.getElementById("test").value;

function save() { 
 localStorage.setItem("note"}, Value);
}

(function() {
 Value = localStorage.getItem("note"));
})();

Basically I tried to save my data from an input, Im using inputs in settings page of another project, and I need settings to reload once my page is reloaded.

<input id=“test” placeholder=“Write Here”>
<button onclick=“save()”>Execute</button>

So I really expected it to reload the value of my settings input, and have the data I saved there when I reloaded my page, but nothing happened. I want it to save my data and reload it on page entering.

  • 5
    You need to get the value after the user clicks. – SLaks Aug 06 '19 at 17:16
  • 3
    Disable “smart quotes” in your editor. It’s `""`, not `“”`. Use the [browser console (dev tools)](https://webmasters.stackexchange.com/q/8525) (hit `F12`) and read any errors; try using the [debugging capabilities](https://developer.mozilla.org/en-US/docs/Mozilla/Debugging/Debugging_JavaScript) of your browser — when does `Value` change? – Sebastian Simon Aug 06 '19 at 17:16
  • @SebastianSimon Oh sorry I was typing this from phone, pc blocked stackoveflow, cant post in pc, sorry. I fixed now. – Furno_Casunate Aug 06 '19 at 17:17
  • is that closing bracket actually there iun the second line of save, or is that a typo from a phone? – Zachary Craig Aug 06 '19 at 17:37

1 Answers1

2

You made a lot of mistakes.... Here is the solution...

HTML

<input id="test" placeholder="Write Here">
<button onclick="save()">Execute</button>

JS

var Item  = document.getElementById("test");

function save() { 
 localStorage.setItem("note", Item.value);
}

(function() {
 Item.value = localStorage.getItem("note");
})();