Diferencia entre revisiones de «Widget:Calculator»
De Wikiexplora
(No se muestran 37 ediciones intermedias de 2 usuarios) | |||
Línea 1: | Línea 1: | ||
<form action="" id="calculator" onsubmit="return false;"> | <form action="" id="calculator" onsubmit="return false;"> | ||
<div> | <div> | ||
− | <div class=" | + | <div class="calculator-boxes"> |
<fieldset> | <fieldset> | ||
− | <legend> | + | <legend>Calculadora de dopihoras</legend> |
− | <label | + | <label><input type="checkbox" id="roundtrip" onclick="roundTripToggle()" name="roundtrip"/>Es ida y vuelta</label> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<br/> | <br/> | ||
− | <label>Distancia horizontal en metros</label> | + | <label id="horizontal-label" class="calculator-label">Distancia horizontal en metros:</label> |
<input type="text" id="horizontal" name="horizontal" value="" /> | <input type="text" id="horizontal" name="horizontal" value="" /> | ||
<br/> | <br/> | ||
− | <label>Metros de ascenso</label> | + | <label id="ascenso-label" name="ascenso-label" class="calculator-label">Metros de ascenso:</label> |
<input type="text" id="ascenso" name="ascenso" value="" /> | <input type="text" id="ascenso" name="ascenso" value="" /> | ||
<br/> | <br/> | ||
− | <label>Metros de descenso</label> | + | <label id="descenso-label" name="descenso-label" class="calculator-label">Metros de descenso:</label> |
<input type="text" id="descenso" name="descenso" value="" /> | <input type="text" id="descenso" name="descenso" value="" /> | ||
+ | <br/> | ||
+ | <label class="calculator-label">Altitud media de toda la ruta:</label> | ||
+ | <input type="text" id="altitude" name="altitude" value="" /> | ||
<div id="totalTime"></div> | <div id="totalTime"></div> | ||
Línea 26: | Línea 26: | ||
</div> | </div> | ||
− | <input type='submit' id='submit' value=' | + | <input type='submit' id='submit' value='Calcular' onclick="calculateTotal()" /> |
</div> | </div> | ||
</form> | </form> | ||
<script> | <script> | ||
− | function calculateTotal() | + | function calculateTotal(){ |
− | { | + | |
var theForm = document.forms["calculator"]; | var theForm = document.forms["calculator"]; | ||
− | var altitude= theForm.elements["altitude"].value; | + | var altitude = parseInt(theForm.elements["altitude"].value); |
− | var horizontal= theForm.elements["horizontal"].value; | + | var horizontal = parseInt(theForm.elements["horizontal"].value); |
− | var ascenso= theForm.elements["ascenso"].value; | + | var ascenso = parseInt(theForm.elements["ascenso"].value); |
− | + | ||
− | var | + | if(theForm.elements["roundtrip"].checked){ |
+ | var descenso = ascenso; | ||
+ | } else { | ||
+ | var descenso = parseInt(theForm.elements["descenso"].value); | ||
+ | } | ||
+ | |||
+ | var total = (horizontal * 0.75 + ascenso * 7.2 + descenso * 2.4) * (4 * Math.pow(10, -12) * Math.pow(altitude , 3) - 9 * Math.pow(10 , -9) * Math.pow(altitude , 2) + 4 * Math.pow(10, -5) * altitude + 0.9999) * (1/3600); | ||
+ | total = Math.round(total * 100) / 100; | ||
+ | |||
+ | if (isNaN(total) || total === ''|| total === 0){ | ||
+ | total = 'Something is not right - please check the values'; | ||
+ | } | ||
+ | else { | ||
+ | total = "Total: "+total+" dopihoras"; | ||
+ | } | ||
+ | |||
//display the result | //display the result | ||
var divobj = document.getElementById('totalTime'); | var divobj = document.getElementById('totalTime'); | ||
divobj.style.display='block'; | divobj.style.display='block'; | ||
− | divobj.innerHTML = | + | divobj.innerHTML = total; |
+ | } | ||
+ | |||
+ | function roundTripToggle(){ | ||
+ | var theForm = document.forms["calculator"]; | ||
+ | var ascensoLabel = document.getElementById('ascenso-label'); | ||
+ | var descensoLabel = document.getElementById('descenso-label'); | ||
+ | var descenso = document.getElementById('descenso'); | ||
+ | var horizontalLabel = document.getElementById('horizontal-label'); | ||
+ | |||
+ | if(theForm.elements["roundtrip"].checked){ | ||
+ | descensoLabel.style.display='none'; | ||
+ | descenso.style.display='none'; | ||
+ | ascensoLabel.innerHTML = 'Metros de ascenso solo ida + metros descenso solo ida:'; | ||
+ | horizontalLabel.innerHTML = 'Distancia horizontal en metros (ida + vuelta, que es lo mismo que ida x 2):'; | ||
+ | |||
+ | } | ||
+ | else { | ||
+ | descensoLabel.style.display='block'; | ||
+ | descenso.style.display='block'; | ||
+ | ascensoLabel.innerHTML = 'Metros de ascenso:'; | ||
+ | horizontalLabel.innerHTML = 'Distancia horizontal en metros:'; | ||
+ | } | ||
+ | |||
} | } | ||
</script> | </script> | ||
+ | |||
+ | <style> | ||
+ | .calculator-label{ | ||
+ | display: block; | ||
+ | } | ||
+ | div#totalTime { | ||
+ | font-size: 110%; | ||
+ | font-weight: bold; | ||
+ | } | ||
+ | </style> |
Revisión actual del 17:00 30 oct 2020
<form action="" id="calculator" onsubmit="return false;">
<fieldset> <legend>Calculadora de dopihoras</legend> <label><input type="checkbox" id="roundtrip" onclick="roundTripToggle()" name="roundtrip"/>Es ida y vuelta</label>
<label id="horizontal-label" class="calculator-label">Distancia horizontal en metros:</label> <input type="text" id="horizontal" name="horizontal" value="" />
<label id="ascenso-label" name="ascenso-label" class="calculator-label">Metros de ascenso:</label> <input type="text" id="ascenso" name="ascenso" value="" />
<label id="descenso-label" name="descenso-label" class="calculator-label">Metros de descenso:</label> <input type="text" id="descenso" name="descenso" value="" />
<label class="calculator-label">Altitud media de toda la ruta:</label> <input type="text" id="altitude" name="altitude" value="" />
</fieldset>
<input type='submit' id='submit' value='Calcular' onclick="calculateTotal()" /> </div>
</form> <script> function calculateTotal(){
var theForm = document.forms["calculator"]; var altitude = parseInt(theForm.elements["altitude"].value); var horizontal = parseInt(theForm.elements["horizontal"].value); var ascenso = parseInt(theForm.elements["ascenso"].value);
if(theForm.elements["roundtrip"].checked){ var descenso = ascenso; } else { var descenso = parseInt(theForm.elements["descenso"].value); } var total = (horizontal * 0.75 + ascenso * 7.2 + descenso * 2.4) * (4 * Math.pow(10, -12) * Math.pow(altitude , 3) - 9 * Math.pow(10 , -9) * Math.pow(altitude , 2) + 4 * Math.pow(10, -5) * altitude + 0.9999) * (1/3600); total = Math.round(total * 100) / 100; if (isNaN(total) || total === || total === 0){ total = 'Something is not right - please check the values'; } else { total = "Total: "+total+" dopihoras"; }
//display the result var divobj = document.getElementById('totalTime'); divobj.style.display='block'; divobj.innerHTML = total;
}
function roundTripToggle(){
var theForm = document.forms["calculator"]; var ascensoLabel = document.getElementById('ascenso-label'); var descensoLabel = document.getElementById('descenso-label'); var descenso = document.getElementById('descenso'); var horizontalLabel = document.getElementById('horizontal-label'); if(theForm.elements["roundtrip"].checked){ descensoLabel.style.display='none'; descenso.style.display='none'; ascensoLabel.innerHTML = 'Metros de ascenso solo ida + metros descenso solo ida:'; horizontalLabel.innerHTML = 'Distancia horizontal en metros (ida + vuelta, que es lo mismo que ida x 2):'; } else { descensoLabel.style.display='block'; descenso.style.display='block'; ascensoLabel.innerHTML = 'Metros de ascenso:'; horizontalLabel.innerHTML = 'Distancia horizontal en metros:'; }
} </script>
<style> .calculator-label{
display: block;
} div#totalTime {
font-size: 110%; font-weight: bold;
} </style>