alakazam Posted May 10, 2010 Report Share Posted May 10, 2010 (edited) ola! tengo un pequeño drama,el cual me ha robado el sueño por varios dias xDD,soy nuevo en lo de html y javascript,y toi buscando la manera de hacer en html un script pa calcular el indice de masa corporal,no tengo drama en hacer que lo calcule,el drama esta cuando intento usar un if para determinar si el peso esta infrapeso,sobrepeso,normal,etc,me dijeron que tenia que cambiar de string a entero,pero no se como...mi codigo va algo asi: <html> <head> <title>IMC</title> <script languaje="JavaScript"> function a(){ var text1=formulario.peso.value; var text2=formulario.altura.value; {document.write("IMC=",a=text1/(text2*text2),if(a<18,5){ {document.write("infrapeso");},"<br>");} if(a<18,5){ document.write("Infrapeso");} else{ if(a>=18,5 && <=25){ document.write("normal");} } </script> </head> <body> <form name=formulario> <input type="text" name="peso"> <input type="text" name="altura"> <input type="button" value="Calcular" onclick="a()"> </form> </body> </html> ojala me puedan ayudar :D desde ya muchas gracias Edited May 10, 2010 by alakazam Link to comment Share on other sites More sharing options...
EL NIGHT Posted May 10, 2010 Report Share Posted May 10, 2010 (edited) Pon todo el código, incluso los ifs que no te funcan. Ah, y encierralos con las etiquetas [*code]Tu codigo[*/code] (sin asteriscos) para que sea más fácil de leer. Saludos. Edited May 10, 2010 by EL NIGHT Link to comment Share on other sites More sharing options...
alakazam Posted May 10, 2010 Author Report Share Posted May 10, 2010 ahi lo edite :D ojala puedas sacarme de mi interrogante :D Link to comment Share on other sites More sharing options...
EL NIGHT Posted May 11, 2010 Report Share Posted May 11, 2010 Encontré algunos errores. - Cuando tomas el valor de una variable, debes poner el document: var text1=document.formulario.peso.value; - Dices que a=text1/(text2*text2), pero en ninguna parte has declarado la variable a. Tampoco creo que puedes tener una variable con el mismo nombre que la función. - ¿Qué es esto? {document.write("IMC=",a=text1/(text2*text2),if(a<18,5){ {document.write("infrapeso");},"<br>");} - if(a>=18,5 && <=25) debería ser if(a>=18,5 && a<=25){ Finalmente, el código funcionando: <html> <head> <title>IMC</title> <script languaje="JavaScript"> function a(){ var text1=document.formulario.peso.value; var text2=document.formulario.altura.value; var imc = text1/(text2*text2); document.write("Tu IMC es de "+imc+"<br />") if(imc < 18,5){ document.write("Infrapeso"); }else if(imc >= 18,5 && imc <= 25){ document.write("normal"); } } </script> </head> <body> <form name="formulario"> <input type="text" name="peso" id="peso"> <input type="text" name="altura" id="altura"> <input type="button" value="Calcular" onclick="a()"> </form> </body> </html> Saludos. Link to comment Share on other sites More sharing options...
alvaroxz Posted May 12, 2010 Report Share Posted May 12, 2010 (edited) Esto va en webmaster no en script php para pasar de un string a entero se hace asi: var text="123"; miEntero = parseInt(text); suerte y pide que lo cambien de lugar Edited May 12, 2010 by alvaroxz Link to comment Share on other sites More sharing options...
alakazam Posted May 12, 2010 Author Report Share Posted May 12, 2010 gracias por la ayuda!!! :D 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