SHOW:
|
|
- or go back to the newest paste.
| 1 | <html> | |
| 2 | <title>::Uso de getElementById::</title> | |
| 3 | <head> | |
| 4 | - | <!-- |
| 4 | + | |
| 5 | - | Autor: Ariel Carraro |
| 5 | + | |
| 6 | - | --> |
| 6 | + | |
| 7 | ||
| 8 | // aqui hago uso de la propiedad getElementById("")
| |
| 9 | var vi=document.getElementById('valor_inicial');
| |
| 10 | var vf=document.getElementById('valor_final');
| |
| 11 | var n=document.getElementById('periodo');
| |
| 12 | ||
| 13 | //muestro los datos en la consola | |
| 14 | console.log("valor final: "+vf.value+" valor inicial:"+vi.value+" periodo: "+n.value);
| |
| 15 | ||
| 16 | // convertir los datos string a number | |
| 17 | vf=parseFloat(vf.value); | |
| 18 | vi=parseFloat(vi.value); | |
| 19 | n=parseInt(n.value); | |
| 20 | ||
| 21 | // esta es la variable que mostrará el resultado | |
| 22 | - | n=parseFloat(n.value); |
| 22 | + | |
| 23 | ||
| 24 | //aqui se hace la operación | |
| 25 | result.value=(Math.pow(vf/vi,1/n)- 1)*100; | |
| 26 | } | |
| 27 | ||
| 28 | - | result.value=Math.pow(vf/vi,1/n) - 1*100; |
| 28 | + | |
| 29 | ||
| 30 | function limpia(){
| |
| 31 | ||
| 32 | document.getElementById('valor_final').value="";
| |
| 33 | document.getElementById('valor_inicial').value="";
| |
| 34 | document.getElementById('periodo').value="";
| |
| 35 | document.getElementById('result').value="";
| |
| 36 | } | |
| 37 | ||
| 38 | </script> | |
| 39 | </head> | |
| 40 | <body> | |
| 41 | <h1>Calcular tasa de interés</h1> | |
| 42 | <div> | |
| 43 | ||
| 44 | valor final: | |
| 45 | <input id="valor_final" type="text" value=""/><br/> | |
| 46 | valor inicial:<input id="valor_inicial" type="text" value=""/><br/> | |
| 47 | periodo:<input id="periodo" type="text" value=""/><br/> | |
| 48 | <button onclick="calculo()">Calcular</button> | |
| 49 | Tasa de interés generado:<b><input id="result" type="text" value=""/></b> | |
| 50 | <button onclick="limpia()">Borrar</button> | |
| 51 | </div> | |
| 52 | </body> | |
| 53 | </html> |