Im currently working with forms and saving the data on Local Storage.
my form is ->
<form id="formy">
<input class="add" id="num1">
<select class="add" id"num2">
<option value="act1"> Try </option>
<option value="act2"> Try2 </option>
<input class="add" id="num3">
<input class="add" id="num4">
</form>
I have 3 inputs and 1 select, I'm able to store the first input, i would like to store in the array ["Hi", "Try2", "LoveCode", "LY"]
But I only get ["Hi"] the first input stored only.
heres js code
const myForm = document.getElementById("formy");
myForm.addEventListener("submit", addTodo);
function addTodo(e) {
e.preventDefault();
const userInput = document.querySelector("add").value;
const userListItem = document.createElement("li");
userListItem.appendChild(document.createTextNode(userInput));
list.appendChild(userListItem);
const myArray = map(listItems, getText);
localStorage.setItem('titols', JSON.stringify(myArray));
}
const listItems = document.getElementsByTagName('li');
function map(arrayLike, fn) {
var ret = [], i = -1, len = arrayLike.length;
while (++i < len) ret[i] = fn(arrayLike[i]);
return ret;
}
Aucun commentaire:
Enregistrer un commentaire