Converting text box value to int - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text


Converting text box value to int

Demo Code

ResultView the demo in separate window

      <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);

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

Related Tutorials