I am trying to get the local storage value for the key 1 , to be set as the value of whatever checkbox is checked, but the value returned by my javascript function appears as [object object] in local storage. Any assistance would be much appreciated, thank you in advance.
<html>
<head>
<script type="text/javascript">
function topic_1_status(){
var status = {
get_value: function(){
return this.value;
}
};
localStorage.setItem(1, status);
}
</script>
</head>
<body>
<div>Topic no.1 </div>
<form action="">
<input type="checkbox" value="learnt" onclick="topic_1_status()" /> Learnt
<input type="checkbox" value="memorised" onclick="topic_1_status()" /> Memorised
<input type="checkbox" value="understood" onclick="topic_1_status()" /> Understood
<input type="checkbox" value="unlearned" onclick="topic_1_status()" /> Unlearned
</body>
</html>
You are getting “object object” because you are store the object ‘status’ instead of the value of the checkbox.
This modifications should give you the results you want.
And the javascript
Also thought mentioning that it seems you want to use radio buttons instead of checkboxes as you plan to only store one item at a time.