title: Create a "calculation form" in javascript
body: <p>so I have a project now, as an addition to my company's website, we want to show our clients how much they can save on gas by buying one of our electric cars, I'm responsible for making it happen, I don't know how to approach this using javascript, can you guys give me a hand? our marketing guy got the idea from <a href="http://www.wattmove.pt/index.php?abrir=sim_poupa" rel="nofollow">this</a> website, that is basically what we want, but I was hoping i could make it a little better on some aspects:</p>
  
  <p>1st-the client wouldn't have to press submit to see the results, as they fill the last field, the calculated part is populated automatically, for this i've been fiddling with the onChange event, unsuccessfully though xD</p>
  
  <p>here's what I have so far, it is not working, at least on dreamweaver's live mode, haven't tested it online yet as I was hoping to develop the whole thing offline: </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function calc(){
  
  var km=document.getElementById(km).value;
  var euro=document.getElementById(euro).value;
  var consumo=document.getElementById(consumo).value;
  
  var cem_km=consumo*euro;
  
  var fossil_day=(cem_km*km)/100;
  return fossil_day;
  }
  
  &lt;/script&gt;
  
  &lt;form name="calc" id="calc"  &gt;
    &lt;p&gt;
    Km/dia
    &lt;input type="text" name="km" id="km" value="" /&gt;
    &lt;/p&gt;
    &lt;p&gt;
    €/Litro
    &lt;input type="text" name="euro" id="euro" value="" /&gt;
    &lt;/p&gt;
    &lt;p&gt;
    Litros/100km
    &lt;input type="text" onChange="calc()" name="consumo" id="consumo" value="" /&gt;
    &lt;/p&gt;
  
     &lt;input type="button" onClick="calc()" name="submit" id="submit" value="Calcular" /&gt;
  
  &lt;script type="text/javascript"&gt;
   var fossil_day = calc();
  document.write('&lt;p&gt;'+fossil_day+'&lt;/p&gt;');
  &lt;/script&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Please note that although I have this already, I wouldnt mind not doing this at all and using another solution, even if it doesnt use forms, I'm just showing what i have already so you can tell me how I'm wrong and how I can have a better approach at it</p>