I want to write a program (JS/HTML) which makes a list out of inputs. If I input the things and press Enter the program is carried out, but my inputs are not shown. To be more precise, the inputs are shown for a moment, but it disappears quickly. Like it glitches
away. I am a beginner programmer and I just can't find the problem. I would appreciate every attempt for help.
function addLebensmittelAndDatum() {
foodsdate.innerHTML += `
<li class="mdl-list__item">
<span class="mdl-list__item-primary-content">
${lebensmittelfield.value}
</span>
<span class="mdl-list__item-primary-content">
${datumfields.value}
</span>
</li>
`;
lebensmittelfield.value += ``;
datumfields.value += ``;
}
.demo-list-item {
width: 300px;
}
.page-content {
padding: 20px 100px;
}
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<!-- Title -->
<span class="mdl-layout-title">Kühlflex</span>
<!-- Add spacer, to align navigation to the right -->
<div class="mdl-layout-spacer"></div>
<!-- Navigation. We hide it in small screens. -->
</div>
</header>
<main class="mdl-layout__content">
<div class="page-content">
<!-- Your content goes here -->
<form onsubmit="addLebensmittelAndDatum()">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="lebensmittelfield">
<label class="mdl-textfield__label" for="lebensmittelfield">Deine Lebensmittel...</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" pattern="-?[0-9+.]*(\.[0-9+.]+)?" id="datumfields">
<label class="mdl-textfield__label" for="datumfields">Datum...</label>
<span class="mdl-textfield__error">Datum eingeben!</span>
</div>
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
Hinzufügen
</button>
</form>
<ul class="demo-list-icon mdl-list" id="foodsdate">
</ul>
</div>
</main>
</div>