I have the following code:
document.getElementById("decimal").addEventListener("click", () => {
if (!inputBox.value.includes(".")) {
inputBox.value += ".";
}
});
<body>
<div class="calculator">
<input type="number" id="inputBox" placeholder="0">
<div>
<button class="decimal" id="decimal">.</button>
</div>
</div>
<script src="script.js"></script>
</body>
When I add an EventListener to the button, a decimal should appear as the last character in the input field. However, because it is set to type="number", the function resets the input field entirely.
How can I add a decimal without resetting the value of the input field?
I have already tried changing the type of the input field to "text", but then the user can type alphabetical values into the input field, which I do not want.