Do calculation based on value input from form - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Do calculation based on value input from form

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function change(){/*  w  ww .j a  v  a  2 s . c o m*/
       var textBox =parseInt(document.getElementById('myTextField').value)
      
       var sec=textBox*(textBox+1)/2
      
       console.log(sec);
}

      </script> 
   </head> 
   <body> 
      <input type="text" id="myTextField"> 
      <input type="button" id="byBtn" value="Change" onclick="change()">  
   </body>
</html>

Related Tutorials