Basically I'm trying to make a page that looks and works like a simple calculator. Can I use html buttons that when clicked add a number to the input field, then when another button is clicked, another number is added to the string.
Here is the html I've used to set up the buttons and "text" entry field. The function writeNumbers is where I intended to write the JS code to make this work. Any ideas on how to set up this functionality would be greatly welcomed!
<p id=demo><p>
<input id="text" type="text">
<button id="seven" type="button" onclick=writeNumbers()>7</button>
<button id="eight" type="button" onclick=writeNumbers()>8</button>
<button id="nine" type="button" onclick=writeNumbers()>9</button>
<br>
<button id="four" type="button" onclick=writeNumbers()>4</button>
<button id="five" type="button" onclick=writeNumbers()>5</button>
<button id="six" type="button" onclick=writeNumbers()>6</button>
<br>
<button id="one" type="button" onclick=writeNumbers()>1</button>
<button id="two" type="button" onclick=writeNumbers()>2</button>
<button id="three" type="button" onclick=writeNumbers()>3</button>
<br>
<button id="cancel" type="button" onclick=writeNumbers()>C</button>
<button id="zero" type="button" onclick=writeNumbers()>0</button>
<button id="equals" type="button" onclick=writeNumbers()>=</button>
I was considering using adding text to the text to the "p" element with 'demo' id as below but thought this was impractical
document.getElementById("demo").innerHTML = "7";
I had also tried using an event listener for the button with a document.write link thing but the number would not be entered into the box. Don't think document.write can be used with input fields. Plus this the code below is not an exact excerpt
document.getElementById("seven").addEventListener("click", document.write("7").);
Tried using the javascript code in the link below, it seemed ideal and could work if I add to it
add-a-string-of-text-into-an-input-field-when-user-clicks-a-button
I hope this helps clarifies what the aim is, please ask if you guys need anything else