0

I'm currently trying to save if someone has checked a HTML checkbox and save it with localStorage in Javascript. Please read over this code and tell me the bugs.

<!DOCTYPE html>
<html>
<head>
<script>
var CheckBox = document.getElementById("Box");
if(localStorage.Box1 == 1) {
document.getElementById("Blank").innerHTML = "Hello";   
}
function Box() {
if(CheckBox.check) {
localStorage.Box1 = 1;
} else {
localStorage.Box1 = 0;
}
}
</script>
</head>    
<body>
<input type="checkbox" id="Box" onclick="Box()">
<p id="Blank"></p>
</body>
</html>
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
  • I've modified your question, please ask one question at a time, and refrain from asking overly-broad questions that are off-topic. – Patrick Roberts Jul 04 '18 at 18:45
  • 3
    At first, you've to move the script from the head to the bottom of the body element, otherwise you're getting errors when trying to refer not-yet-existing elements. – Teemu Jul 04 '18 at 18:45
  • 1
    Please try using the [debugging capabilities](https://developer.mozilla.org/en-US/docs/Mozilla/Debugging/Debugging_JavaScript) of your browser. – Sebastian Simon Jul 04 '18 at 18:46

0 Answers0