How do I add Text before my answer in the text box using setAttribute but only after the resullt has been printed

I want it to read the-number-that-has-been-computed) where the-number-that-has-been-computed is the result of the addition of the first two text boxes( I am also using window.onload that is why my script is in the head of the file.

function setUpEvents() {
  function add_number() {
    var first_number = parseInt(document.getElementById("tb1").value);
    var second_number = parseInt(document.getElementById("tb2").value);
    var result = first_number + second_number;
    document.getElementById("tb3").value = result;
  };
}
window.onload = function() {
  setUpEvents();
};
<div>
  <h1>Add two number using text box as input using javascript</h1>
</div>
Enter First Number : <br>
<input type="text" id="tb1" name="TextBox1">
<br> Enter Second Number : <br>
<input type="text" id="tb2" name="TextBox2">
<br> Result : <br>
<input type="text" id="tb3" name="TextBox3">
<br>
<input type="button" name="b1" value="GO" onclick="add_number()">

95 thoughts on “How do I add Text before my answer in the text box using setAttribute but only after the resullt has been printed”

Leave a Comment