title: cannot convert input text to int in JavaScript
body: <p>I am trying to sort a table in HTML by clicking the table header. The sorting is fine for strings, but when comparing numbers, it evaluates "10" &lt; "2". Obviously, I'm comparing strings, but I can't get a number out of my table cell. Here's a working example of what's going on:</p>
  
  <pre><code> &lt;script type="text/javascript" &gt;
        function sortBy() {
            var table = document.getElementById("table");
            var rows = table.getElementsByTagName("tr");
            var number = rows[1].getElementsByTagName("td")[0].innerHTML;
            document.write(number);  // This should be printing "7".
        }
   &lt;/script&gt;
  
   &lt;?php 
        echo "&lt;table id='table'&gt;
           &lt;thead&gt;&lt;tr&gt;&lt;th onclick='sortBy()'&gt;CLICK ME&lt;/th&gt;&lt;/thead&gt;&lt;/tr&gt;
           &lt;tbody&gt;&lt;td&gt;&lt;input readonly value='7'&gt;&lt;/td&gt;&lt;/tbody&gt;";
   ?&gt;
  </code></pre>
  
  <p>In this example, I'm trying to get the integer <code>7</code>. I've tried <code>parseInt(number)</code>, but that evaluates to <code>NaN</code>, so I tried writing what <code>number</code> was and it prints a textfield instead of the textfield's content. I've checked this by printing <code>number.length</code>, and I get <code>29</code>, rather than <code>1</code>.</p>
  
  <p>I've tried <code>number.value</code> but that's <code>undefined</code>. </p>
  
  <p>I've tried replacing <code>.innerHTML</code> with <code>.value</code>, but that's <code>undefined</code> too. </p>
  
  <p>Is there some way I can convert this into a number? Or at least strip away the html tags and such? I realize I can rig up my own compare logic using the string and it's length ( if (A.length > B.length) { A's bigger } else { compare like normal } ), but that's messy and won't help me to understand this problem.</p>