Codey93 Codey93 - 5 months ago 14
HTML Question

Javascript, div on click multiple numbers in input field

I'm trying to create a

JavaScript
to modify the number in my input field.

Example:

<input value="0">


And then a simple button or div with a
JavasSript
click function.

<button>Add +10</button>


After clicking on the button:

<input value="10">


Does someone have a place I can read and learn to create this, or any tips to get me started. I know very little
JavaScript
, but I wish to learn.

Answer

You can try this

<input value="0" id="id">

give a id to input field

on button click call a function

<button onclick="myFunction()">Add +10</button>

<script>
    function myFunction() {
        document.getElementById("id").value = parseInt(document.getElementById("id").value) +10;
    }

</script>