I am making a to-do list in javascript but I am getting an error: Uncaught ReferenceError: itemsjson is not defined.
I Have set my get.item null after that added .push
Please can anyone solve the issue
thanks
Note: i’m using Bootstrap for HTML
<!doctype html>
<html lang="en">
<div class="form">
<label for="formGroupExampleInput" class="form-label">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input placeholder">
<label for="formGroupExampleInput2" class="form-label">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input placeholder"> <br>
<button type="submit" id="add" class="btn btn-primary">Sign in</button>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Item Description</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>Parvinder</td>
<td>Hello, Parvinder how are you?</td>
<td><button type="button" class="btn btn-primary btn-sm">Small button</button></td>
</tr>
</tbody>
</table>
<script>
tatti = document.getElementById("add");
tatti.addEventListener("click", () => {
console.log("updating");
tit = document.getElementById('formGroupExampleInput').value;
desc = document.getElementById('formGroupExampleInput2').value;
if (localStorage.getItem(itemsjson)==null){
itemjsonArray = [];
itemjsonArray.push([tit,desc]);
localStorage.setItem('itemjson', JSON.stringify(itemsjsonArray));
}
})
</script>
</center>
</html>
2
Answers
will search for valiable name itemsjson
it should be like this
You forget to put quotes in
if(localStorage.getItem(itemsjson) ==null)
.