Advertisement
ARIELCARRARO

interes.html

Aug 11th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <html>
  2. <title>::Uso de getElementById::</title>
  3. <head>
  4. <!--
  5. Autor: Ariel Carraro
  6. -->
  7. <script type="text/javascript" language="javascript">
  8. console.log('aqui se crea la función')
  9. function calculo(){
  10.  
  11. // aqui hago uso de la propiedad getElementById("")
  12. var vi=document.getElementById('valor_inicial');
  13. var vf=document.getElementById('valor_final');
  14. var n=document.getElementById('periodo');
  15.  
  16. //muestro los datos en la consola
  17. console.log("valor final: "+vf.value+" valor inicial:"+vi.value+" periodo: "+n.value);
  18.  
  19. // convertir los datos string a number
  20. vf=parseFloat(vf.value);
  21. vi=parseFloat(vi.value);
  22. n=parseFloat(n.value);
  23.  
  24. // esta es la variable que mostrará el resultado
  25. var result=document.getElementById('result');
  26.  
  27. //aqui se hace la operación
  28. result.value=Math.pow(vf/vi,1/n) - 1*100;
  29. }
  30.  
  31.  
  32.  
  33. function limpia(){
  34.  
  35. document.getElementById('valor_final').value="";
  36. document.getElementById('valor_inicial').value="";
  37. document.getElementById('periodo').value="";
  38. document.getElementById('result').value="";
  39. }
  40.  
  41. </script>
  42. </head>
  43. <body>
  44. <h1>Calcular tasa de interés</h1>
  45. <div>
  46.  
  47. valor final:
  48. <input id="valor_final" type="text" value=""/><br/>
  49. valor inicial:<input id="valor_inicial" type="text" value=""/><br/>
  50. periodo:<input id="periodo" type="text" value=""/><br/>
  51. <button onclick="calculo()">Calcular</button>
  52. Tasa de interés generado:<b><input id="result" type="text" value=""/></b>
  53. <button onclick="limpia()">Borrar</button>
  54. </div>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement