Cálculo de Velocidade

HTML
<body> <form id="formulario"> <fieldset> <legend>Cálculo de velocidade</legend> <label for="espaço">espaço (metros):</label> <input type="text" name="espaço"/> <label for="tempo">tempo (segundos):</label> <input type="text" name="tempo"/> <label for="velocidade">velocidade (m/s):</label> <input type="text" name="velocidade" disabled="disabled"/> <a href="#" onclick="calcular()">Calcular</a> </fieldset> </form> </body>
CSS
img, table { width:165px; } fieldset { width:140px; } label { display:block; float:left;} label, input {width:68px; margin:3px 0; } th, td {border:1px solid #ccc; font-size:0.8em;}
JAVASCRIPT
calcular = function(){ var formulario = document.getElementById("formulario"); var espaço = +formulario.espaço.value; var tempo = +formulario.tempo.value; var velocidade= espaço/tempo; formulario.velocidade.value = velocidade.toFixed(2); }
Expand for more options Login