Jump to content

Ayuda Pliss con esto


Recommended Posts

Amigos

 

Sorry que sea majadero , pero estoy buelto loco con esto, estoy haciendo un calculadora para medir el HUella CO2, lo trabaje en HTML y Java y quiero que al final de los resultados me salga con decimales, me pueden ayudar ?

 

HTML


<body>
<form id="form_calculadora" name="form_calculadora"><div>
<h1>SCOPE1</h1>
<table width="600" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td width="329" height="25">Consumo de combustible en vehículos</td>
   <td width="150"><input name="combustuble_vh" type="text" id="combustuble_vh" value="0" onkeyup="scope1()" onkeypress="return validaNum(event);"/></td>
   <td width="121"> </td>
 </tr>
 <tr>
   <td height="25">Consumo de combustibles en maquinarias estacionarias productivas</td>
   <td><label>
     <input name="combustible_maq" type="text" id="combustible_maq" value="0" onkeyup="scope1()" onkeypress="return validaNum(event);" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Consumo combustible en calefactores</td>
   <td><label>
     <input name="combustible_calefac" type="text" id="combustible_calefac" value="0" onkeyup="scope1()" onkeypress="return validaNum(event);" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Consumo de gases refrigerantes</td>
   <td><label>
     <input name="gases_refri" type="text" id="gases_refri" value="0" onkeyup="scope1()" onkeypress="return validaNum(event);" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25"><strong>Huella de carbono Total:</strong></td>
   <td><label>
     <input name="totalscope1" type="text" id="totalscope1" value="0" readonly="readonly" />
   </label></td>
   <td> </td>
 </tr>
 </table>
</div>
<div>
<h1>SCOPE2</h1>
 <table width="600" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td width="427" height="25">Electricidad de sistema eléctrico</td>
   <td width="173"><input name="sistema_electric" type="text" id="sistema_electric" value="0" onkeypress="return validaNum(event);" onkeyup="scope2()" /></td>
   <td width="173"> </td>
 </tr>
 <tr>
   <td height="25"><strong>Huella de carbono:</strong></td>
   <td><label>
     <input name="totalscope2" type="text" id="totalscope2" value="0" />
   </label></td>
   <td> </td>
 </tr>
 </table>
</div>
 <div>
 <h1>SCOPE3</h1>
 <table width="600" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td width="427" height="25">Transporte de Materias Primas </td>
   <td width="173"><label>
     <input name="transMaterPrimas" type="text" id="transMaterPrimas" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()" />
   </label></td>
   <td width="173"> </td>
 </tr>
 <tr>
   <td height="25">Transporte de Insumos de producción </td>
   <td><label>
     <input name="transInsumosProduc" type="text" id="transInsumosProduc" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()"  />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Transporte de Insumos de Oficina y aseo </td>
   <td><label>
     <input name="transInsuOfiAseo" type="text" id="transInsuOfiAseo" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Transporte de Residuos </td>
   <td><label>
     <input name="transResiduos" type="text" id="transResiduos" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Transporte de trabajadores</td>
   <td><label>
     <input name="transTrabajadores" type="text" id="transTrabajadores" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Viajes de negocios </td>
   <td><label>
     <input name="viajesNegocios" type="text" id="viajesNegocios" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25">Residuos a reciclaje</td>
   <td><label>
     <input name="residuosReciclaje" type="text" id="residuosReciclaje" value="0" onkeypress="return validaNum(event);" onkeyup="scope3()" />
   </label></td>
   <td> </td>
 </tr>
 <tr>
   <td height="25"><strong>Huella de carbono Total:</strong></td>
   <td><label>
     <input name="totalscope3" type="text" id="totalscope3" value="0" readonly="readonly" />
   </label></td>
   <td> </td>
 </tr>
 </table>
 </div>
<div>
<!-- <input name="calcular" type="button" value="Calcular" />-->
</div>
<div>
 <h1>Emite un total de:<span id="totalHuellas">0</span> ton CO2-e/año.</h1></div>
</form>
</body>

 

JAVA

// JavaScript Document
function validaNum(evt){
//asignamos el valor de la tecla a keynum
if(window.event){// IE
keynum = evt.keyCode;
}else{
keynum = evt.which;
}
//comprobamos si se encuentra en el rango
if((keynum>47 && keynum<58)|| keynum==8 || keynum==0 ){
return true;
}else{
return false;
}
}
/* CALCULAR DATOS */
function scope1()
{
ConsumoCombustibleVH = document.form_calculadora.combustuble_vh.value;
ConsumoCombustibleMQ = document.form_calculadora.combustible_maq.value;
ConsumoCombustibleCalefa = document.form_calculadora.combustible_calefac.value;
ConsumoGasesRefri = document.form_calculadora.gases_refri.value;

valor = (((ConsumoCombustibleVH*500)+(ConsumoCombustibleMQ*500)+(ConsumoCombustibleCalefa*500)+(ConsumoGasesRefri*500)+400)*500)/2;
valor = Math.round(valor*1000000)/1000000;
if(!isNaN(valor) && valor !='Infinity')
{
document.form_calculadora.totalscope1.value= valor;
}
calcularTotal(); 
}
/* CALCULAR DATOS SCOPE2 */
function scope2()
{
SistemaElectrico = document.form_calculadora.sistema_electric.value;

valor = ((SistemaElectrico*500)+500)/2;
valor = Math.round(valor*1000000)/1000000;
if(!isNaN(valor) && valor != 'Infinity')
{
document.form_calculadora.totalscope2.value = valor;
}
calcularTotal();

}
/* CALCULAR DATOS SCOPE3 */
function scope3()
{
TransporteMateriasPrim = document.form_calculadora.transMaterPrimas.value;
TransporteInsumosProduc = document.form_calculadora.transInsumosProduc.value;
TransporteInsumosOfi = document.form_calculadora.transInsuOfiAseo.value;
TransporteResiduos = document.form_calculadora.transResiduos.value;
TransporteTrabaja = document.form_calculadora.transTrabajadores.value;
ViajesNegocios = document.form_calculadora.viajesNegocios.value;
ResiduosResiclaje = document.form_calculadora.residuosReciclaje.value;

valor = ((TransporteMateriasPrim*500)+(TransporteInsumosProduc*500)+(TransporteInsumosOfi*500)+(TransporteResiduos*500)+(TransporteTrabaja*500)+(ViajesNegocios*500)+(ResiduosResiclaje*500)+700)/2;
valor = Math.round(valor*1000000)/1000000;
if(!isNaN(valor) && valor != 'Infinity')
{
document.form_calculadora.totalscope3.value = valor;
}
calcularTotal();
}

function calcularTotal()
{
valorTotalscope1 = parseFloat(document.form_calculadora.totalscope1.value);
valorTotalscope2 = parseFloat(document.form_calculadora.totalscope2.value);
valorTotalscope3 = parseFloat(document.form_calculadora.totalscope3.value);


valorCalculoTotal = valorTotalscope1 + valorTotalscope2 + valorTotalscope3;
//alert(valorCalculoTotal);
valorCalculoTotal = Math.round(valorCalculoTotal*1000)/1000;
if(!isNaN(valor) && valor != 'Infinity')
{
document.getElementById('totalHuellas').innerHTML = valorCalculoTotal;
}
}

Edited by maxuber
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...