I want to input numbers using buttons into the textbox how to do that?
I have a problem on displaying buttons to textbox, I can only store one function in one button for example <button onclick="getNumber(1)">1</button>
function calc() {
var a, b, c;
a = Number(document.getElementById('num1').value);
b = Number(document.getElementById('num2').value);
c = document.getElementById('operators').value;
if (c === '+') {
x = document.getElementById('ans').value = (a + b);
}
if (c === '-') {
x = document.getElementById('ans').value = (a - b);
}
if (c === '*') {
x = document.getElementById('ans').value = (a * b);
}
if (c === '/') {
x = document.getElementById('ans').value = (a / b);
}
}
<input type="text" id="num1"><br>
<input type="text" id="num2"><br>
<select id="operators">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<br>
<button onclick="calc()">=</button><br>
<input type="text" id="ans">