Format Numbers in JavaScript
<p>I have a web page that allows a user to enter values into fields. When a user updates a field, I want to automatically update the total displayed to the user. Because the input fields are dynamically generated, I created a JavaScript function called "update". A sample of my code is shown here:</p>

<pre><code>&lt;input type="text" id="myField1" onchange="return update(this);" /&gt;
&lt;input type="text" id="myField2" onchange="return update(this);" /&gt;
&lt;span id="totalCount"&gt;&lt;/span&gt;

var total = 0;
function update(e) {
  var v = $(e).val();
  if (parseInt(v) != NaN) {
    total = total + v;
    $("#totalCount").html(total);       
  }
  return false;
}
</code></pre>

<p>When a user enters "2" into "myField1", "02" is displayed in the "totalCount" element. In reality, I would like to just display "2". How do I do this in JavaScript while taking into a account odd entries?</p>

<p>Thanks!</p>
