I have a simple code that add two numbers. The result is displayed in a textbox. How can I display the result in a div, rather than a textbox?
Here is my current code, which displays the result in a textbox.
function sum() {
var field1 = document.getElementById('txt1').value;
var field2 = document.getElementById('txt2').value;
var field1V = parseInt(field1);
var field2V = parseInt(field2);
var result = field1V + field2V;
if (!isNaN(result)) {
document.getElementById('txt3').value = result;
}
}
<input type="text" placeholder="Type number" id="txt1" onkeyup="sum();" />
<input type="text" placeholder="Type number" id="txt2" onkeyup="sum();" />
Result: <input type="text" id="txt3" readonly />