I think the intention is clear: Either you press one button or the other to add the item you typed into the input-field to one or the other shopping list.
However, no matter what or if I write something at all, if I press one of the buttons, it will just add "null" to the list.
Why is that?
function sortItem1() {
document.getElementById("addToMarket").addEventListener("click", addToMarketList);
}
function sortItem2() {
document.getElementById("addToOnline").addEventListener("click", addToOnlineList);
}
var gottaBuy = document.getElementById("item");
var listForMarket = " ";
var listForOnlineShop = " ";
function addToMarketList() {
listForMarket = listForMarket + "<li>" + gottaBuy + "</li>";
document.getElementById("marketList").innerHTML = listForMarket;
document.getElementById("item").value = " ";
}
function addToOnlineList() {
listForOnlineShop = listForOnlineShop + "<li>" + gottaBuy + "</li>"
document.getElementById("onlineList").innerHTML = listForOnlineShop;
document.getElementById("item").value = " ";
}
window.addEventListener("load", sortItem1);
window.addEventListener("load", sortItem2);
<h1>What would you like to add?</h1>
<input type="text" id="item" />
<button type="button" id="addToMarket">Markt</button>
<button type="button" id="addToOnline">Online</button>
<h2>Buy at a store:</h2>
<ul id="marketList"></ul>
<h2>Buy online:</h2>
<ul id="onlineList"></ul>