Converting text box value to int - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Converting text box value to int

Demo Code

ResultView the demo in separate window

<html>
   <head>
      <title>to int()</title> 
      <script type="text/javascript">
function doResults()// w w  w  .j  av  a 2 s.  c  o m
{
    var element = document.getElementById('results'),
        value = +(element.value) || 0;
    
    element.value = value;
    console.log("The value is " + value);
}

      </script>
   </head> 
   <body> 
      <input type="text" id="results" class="form-control" name="results" placeholder="results"> 
      <button onclick="doResults();">Check Results</button> 
   </body>
</html>

Related Tutorials