JS

HOW TO ADD TWO NUMBERS IN JAVASCRIPT

<form onsubmit="return add();">   X = <input type="number" id="varX"/>   Y = <input type="number" id="varY"/>   X+Y = <input type="number" id="varR"/>   <input type="submit" value="Add"/> </form>

ADD NUMBERS HTML FORM

01

function add () {   GET VALUES FROM TEXT BOXES   var x = document.getElementById   ("varX").value;   var y = document.getElementById   ("varY").value;

JAVASCRIPT ADD NUMBERS

02

  ADD NUMBERS - X & Y ARE STRINGS!   PARSE TO INT BEFORE ADD   result = parseInt(x) + parseInt(y);

  OUTPUT RESULT      document.getElementById   ("varR").value = result;   return false; }