Diferencia entre revisiones de «Widget:Calculator»
De Wikiexplora
Línea 19: | Línea 19: | ||
<input type="text" id="descenso" name="descenso" value="" /> | <input type="text" id="descenso" name="descenso" value="" /> | ||
− | <div id=" | + | <div id="totalTime"></div> |
</fieldset> | </fieldset> | ||
Línea 29: | Línea 29: | ||
</div> | </div> | ||
</form> | </form> | ||
+ | <script> | ||
+ | function calculateTotal() | ||
+ | { | ||
+ | var theForm = document.forms["calculator"]; | ||
+ | var altitude= theForm.elements["altitude"]; | ||
+ | var horizontal= theForm.elements["horizontal"]; | ||
+ | var ascenso= theForm.elements["ascenso"]; | ||
+ | var descenso= theForm.elements["descenso"]; | ||
+ | |||
+ | var total= altitude + altitude + horizontal + ascenso + descenso; | ||
+ | |||
+ | //display the result | ||
+ | var divobj = document.getElementById('totalTime'); | ||
+ | divobj.style.display='block'; | ||
+ | divobj.innerHTML = "Total time: "+total; | ||
+ | |||
+ | } | ||
+ | </script> |
Revisión del 22:54 18 ago 2017
<form action="" id="calculator" onsubmit="return false;">
<fieldset> <legend>Calculate the time</legend> <label class='radiolabel'><input type="radio" name="selectedcake" value="RoundTrip" onclick="calculateTotal()" />Is a round trip</label>
<label>Mean altitude of the whole route</label> <input type="text" id="altitude" name="altitude" value="" />
<label>Distancia horizontal en metros</label> <input type="text" id="horizontal" name="horizontal" value="" />
<label>Metros de ascenso</label> <input type="text" id="ascenso" name="ascenso" value="" />
<label>Metros de descenso</label> <input type="text" id="descenso" name="descenso" value="" />
</fieldset>
<input type='submit' id='submit' value='Submit' onclick="calculateTotal()" /> </div>
</form> <script> function calculateTotal() {
var theForm = document.forms["calculator"]; var altitude= theForm.elements["altitude"]; var horizontal= theForm.elements["horizontal"]; var ascenso= theForm.elements["ascenso"]; var descenso= theForm.elements["descenso"];
var total= altitude + altitude + horizontal + ascenso + descenso; //display the result var divobj = document.getElementById('totalTime'); divobj.style.display='block'; divobj.innerHTML = "Total time: "+total;
} </script>