Advertisement
Hiteshw11

Accepting And Adding Two Numbers in JavaScript

Mar 26th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2.     <html>
  3.         <body>
  4.             <input type="text" placeholder="Enter first number" id="fnum"/>
  5.             <br>
  6.             <input type="text" placeholder="Enter second number" id="snum"/>
  7.             <br>
  8.             <button type="button" onclick="addition()">Submit</button>
  9.        
  10.         <script>
  11.             function addition()
  12.             {
  13.             var a=Number(document.getElementById('fnum').value);
  14.             var b=Number(document.getElementById('snum').value);
  15.             var c=a+b;
  16.             document.write("The sum is "+c);
  17.             }
  18.         </script>
  19.  
  20.         </body>
  21.     </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement