Ver Mensaje Individual
  #9 (permalink)  
Antiguo 19/05/2014, 10:28
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Respuesta: Como crear boton de calculo?

Ten en cuenta que hay interes simple y compuesto..... y lo hare como INTERES COMPUESTO ó SIMPLE (ambos) en JS:

Código Javascript:
Ver original
  1. <html>
  2. <head>     
  3. <script language="JavaScript"> 
  4.     function calcular()
  5.     {
  6.         var precio=  parseFloat( document.getElementById("precio_no_tax").value);  
  7.         var tax = 1+(parseFloat( document.getElementById("tax").value)/100);                   
  8.         var interes= (parseFloat( document.getElementById("interes").value)/100);      
  9.         var cuotas=  parseInt( document.getElementById("cuotas").value);               
  10.        
  11.         var interes_tipo= document.getElementById("interes_tipo").value;
  12.        
  13.         if (interes_tipo =='compuesto')    
  14.             // Calculo el interes como interes *compuesto*
  15.             var interes_total = Math.pow(1+interes,cuotas);
  16.         else       
  17.             // Calculo el interes como interes *simple*
  18.             var interes_total = 1+(interes * cuotas);
  19.            
  20.                
  21.         var total = document.getElementById("total").value = (precio*tax*interes_total)/cuotas;            
  22.     }  
  23. </script>  
  24. </head>
  25.  
  26.  
  27. <body onload="calcular();">
  28.  
  29. <form method="POST" action="tu_script.php" name="form">
  30. <tbody>
  31.  
  32. <tr>
  33. <td>Precio(sin iva):</td>
  34. <td><input type="text" id="precio_no_tax" name="price_notax" value="100" size="5" onkeyup="calcular();"></td>
  35. </tr>
  36.  
  37. <tr>
  38. <td>Cuotas:</td>
  39. <td>
  40.     <select id="cuotas" onchange="calcular();">
  41.         <option value="6" selected>6</option>      
  42.         <option value="12">12</option>
  43.         <option value="36">36</option>
  44.     </select>
  45.        
  46. </td>
  47. </tr>
  48.  
  49. <tr>
  50. <td>Interes %</td>
  51. <td><input type="text" id="interes" value="3" size="1" onchange="calcular();"></td>
  52. </tr>
  53. <tr>
  54.  
  55. <tr>
  56. <td>Tipo interes</td>
  57. <td>
  58.     <select id="interes_tipo" onchange="calcular();">
  59.         <option value="simple" selected>Simple</option>    
  60.         <option value="compuesto">Compuesto</option>        
  61.     </select>
  62.        
  63. </td>
  64. </tr>
  65.  
  66.  
  67. <tr>
  68. <td>Iva:</td>
  69. <td>
  70.     <select id="tax" onchange="calcular();">
  71.         <option value="0" selected>Ninguna</option>
  72.         <option value="16">16</option>
  73.         <option value="30">30</option>
  74.     </select>
  75.        
  76. </td>
  77. </tr>
  78.  
  79. <tr>
  80. <td>Total:</td>
  81. <td><input type="text" name="total" value="" id="total" size="3"></td>
  82. </tr>
  83.  
  84. </body>
  85.  
  86.  
  87. </html>
__________________
Salu2!

Última edición por Italico76; 19/05/2014 a las 10:51