title: How can I show a value in a javascript onchange?
body: <p>I did an app in rails using javascript to do a sum.</p>
  
  <p>But I have a problem when my value is nil or empty won't work and shows "NaN".</p>
  
  <p>Could be a way to fix this or maybe show " 0 " insteaf of "NaN"?</p>
  
  <p>Here is my controller</p>
  
  <pre><code> def
     @soles = Client.sum(:money)
   end
  </code></pre>
  
  <p>The problem is when @soles is nil , I need a way to show 0.</p>
  
  <pre><code> &lt;input type="text" id="my_input1" value="&lt;%=  @soles  %&gt;" /&gt;
   &lt;input type="text" id="my_input2" onchange="doMath();" /&gt;
   &lt;input type="text" id="sum" /&gt;
  
   &lt;script type="text/javascript"&gt;
  function doMath()
  {
      // Capture the entered values of two input boxes
      var my_input1 = document.getElementById('my_input1').value;
      var my_input2 = document.getElementById('my_input2').value;
  
      // Add them together and display
      var sum = parseInt(my_input1) + parseInt(my_input2);
      document.getElementById('sum').value = sum;
  }
  </code></pre>
  
  <p></p>
  
  <p>I tried but doesn't work</p>
  
  <pre><code>@soles = 0
  </code></pre>
  
  <p>I will really appreciate help.</p>
  
  <p>Thanks</p>