Basicamente se recoje un dato de un formulario y da un resultado segun el dato del input
Código HTML:
Ver original
var ml=" Mililitros"; var l=" Litros"; var g=" Gramos"; var mg=" Miligramos"; var k=" Kilogramos"; function cloro() { var UI=document.getElementById('entradaCloro').value; if(isNaN(UI)){return false;} var agu = UI*80/100; var hip = UI*20/100; var fos = UI*0.25/100; var car = UI*0.25/100; var per = UI*0.30/100; if (UI<=1){ agu = agu*1000 + ml; hip = hip*1000 + ml; fos = fos*1000 + g; car = car*1000 + g; per = per*1000 + ml; } else{ agu= agu + l; hip= hip + l; if (fos*1000>=1000){fos = fos + k;}else{fos=fos*1000+g;} if (car*1000>=1000){car = car + k;}else{car=car*1000+g;} if (per*1000>=1000){per = per + l;}else{per=per*1000+ml;} } var resul = "1.- Agua - H2O" + " = "+agu+"<br>"+ "2.- Hipoclorito - ClO−" + " = "+hip+"<br>"+ "3.- Fosfato Trisodico" + " = "+fos+"<br>"+ "4.- Carbonato ASH" + " = "+car+"<br>"+ "5.- Perfume Hiposodico" + " = "+per+"<br>"; document.getElementById('salida').innerHTML=resul; } function detergente() { var UI=document.getElementById('entradaDetergenteRopa').value; if(isNaN(UI)){return false;} var tex = UI*14.1/100; var pas = UI*0.75/100; var ash = UI*0.2/100; var sal = UI*3/100; var agu = UI*82/100; var col = UI*0.2/100; var fra = "Al Gusto"; var form = UI*0.2/100; if (UI<=1){ tex = tex*1000 + " ml"; pas = pas*1000 + " ml"; ash= ash*1000 + " ml"; sal= sal*1000 + " gr"; agu= agu*1000 + " ml"; col= col*1000 + " gr"; form= form*1000 + " gr"; } else{ tex = tex + " Litros"; pas = pas + " Litros"; ash = ash + " Kilos"; } var resul = "1.- Texapon" + " = "+tex+"<br>"+ "2.- Pasta Sulfonica" + " = "+pas+"<br>"+ "3.- Soda ASH Light" + " = "+ash+"<br>"+ "4.- Sal" + " = "+sal+"<br>"+ "5.- Agua - H2O" + " = "+agu+"<br>"+ "6.- Color" + " = "+col+"<br>"+ "7.- Fragancia" + " = "+fra+"<br>"+ "8.- Formol o Benzoato de Sodio" + " = "+form+"<br>"; document.getElementById('salida').innerHTML=resul; } function desinfectantePisos() { var UI=document.getElementById('entradaDesinfectantePisos').value; if(isNaN(UI)){return false;} var agu = UI*80/100; var hip = UI*20/100; var fos = UI*0.25/100; var car = UI*0.25/100; var per = UI*0.30/100; if (UI<=1){ agu = agu*1000 + ml; hip = hip*1000 + ml; fos = fos*1000 + g; car = car*1000 + g; per = per*1000 + ml; } else{ agu= agu + l; hip= hip + l; if (fos*1000>=1000){fos = fos + k;}else{fos=fos*1000+g;} if (car*1000>=1000){car = car + k;}else{car=car*1000+g;} if (per*1000>=1000){per = per + l;}else{per=per*1000+ml;} } var resul = "1.- Agua - H2O" + " = "+agu+"<br>"+ "2.- Hipoclorito - ClO−" + " = "+hip+"<br>"+ "3.- Fosfato Trisodico" + " = "+fos+"<br>"+ "4.- Carbonato ASH" + " = "+car+"<br>"+ "5.- Perfume Hiposodico" + " = "+per+"<br>"; document.getElementById('salida').innerHTML=resul; } function entrada(){ if(UI=document.getElementById('entradaDetergenteRopa')){detergente();} else if(UI=document.getElementById('entradaCloro')) {cloro();} else if(UI=document.getElementById('entradaDesinfectantePisos')) {desinfectantePisos();} } function validarSiNumero(UI){ if (!/^([0.1-9])*$/.test(UI)){ //alert("El valor " + UI + " no es un número valido, intente utilizar numeros desde 0.1 hasta la cantidad de litros que usted desee fabricar"); document.getElementById('salida').innerHTML= alerta; } else if (UI==""){ var nada = "NO HA ESCRITO NADA INTENTE UTILIZAR NUMEROS DESDE 0.1 HASTA LA CANTIDAD DE PRODUCTO QUE USTED DESEE FABRICAR"; document.getElementById('salida').innerHTML= nada;} else { entrada(); }}