maxuber Posted May 7, 2012 Report Share Posted May 7, 2012 Estimados Solicito su ayuda por que ando en busqueda de como hacer una mini calculadora, como por ejemplo, en un formulario ingreso xx cantidad multiplicado por xxx cantidad, me arroje xx resultado. Espero que me haya explicado bien. Saludos Link to comment Share on other sites More sharing options...
cañangasñangas Posted May 7, 2012 Report Share Posted May 7, 2012 en que lenguaje mi estimado? Link to comment Share on other sites More sharing options...
maxuber Posted May 7, 2012 Author Report Share Posted May 7, 2012 No tengo preferencia, html, php o java Link to comment Share on other sites More sharing options...
cañangasñangas Posted May 7, 2012 Report Share Posted May 7, 2012 (edited) <input type="text" id="a"> <select id="opt"><option value="1">+</option><option value="2">-</option><option value="3">x</option><option value="4">/</option></select> <input type="text" id="b"><input type="button" onclick="operar()" value="Calcular"><br/> <input type="text" id="result" value="Resultado aqui"> <script type="text/javascript">function operar(){n1=parseInt(document.getElementById("a").value);n2=parseInt(document.getElementById("b").value);opt = parseInt(document.getElementById("opt").value);if(opt == 1){r=n1+n2;}else if(opt == 2){r=n1-n2;}else if(opt == 3){r=n1*n2;}else{if(n2 == 0){ r="Error"; }else{ r=n1/n2; }}document.getElementById("result").value=r;} </script> Edited May 10, 2012 by cañangasñangas Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now