Foros del Web » Programando para Internet » Javascript »

Conversor de pesetas a euros

Estas en el tema de Conversor de pesetas a euros en el foro de Javascript en Foros del Web. Decidme por favor si este codigo sta bien //La funcion validar es para validar q no se introduzcan caracteres alfabeticos en el campo pesetas y ...
  #1 (permalink)  
Antiguo 12/03/2006, 12:49
 
Fecha de Ingreso: marzo-2006
Mensajes: 1
Antigüedad: 18 años, 1 mes
Puntos: 0
Conversor de pesetas a euros

Decidme por favor si este codigo sta bien
//La funcion validar es para validar q no se introduzcan caracteres alfabeticos en el campo pesetas y en el campo euros.
// al mostrar por pantalla el resultado me muestra NaN y e probao d todo y me sigue saliendo NaN
xq me pone esto cuando le estoy validando q no introduzca caracteres alfabeticos en el campo euros y en el campo pesetas.
xfavor responder si sta bien o mal el codigo q me juego el aprobao.
<html>
<script language="Javascript">
var checkStr;
var checkStri;
var peseEur;
var euroPese;
function validar(formulario)
{
var checkOK = "0123456789";
checkStr = formulario.pesetas.value;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0; i < checkStr.length; i++) {
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length) {
allValid = false;
break;
}
allNum += ch;
}
if (!allValid) {
alert("Escriba sólo dígitos en el campo \"Pesetas\".");
formulario.pesetas.focus();
return (false);
}
var checkOKK = "0123456789";
checkStri = formulario.euros.value;
var allValidd = true;
var decPointss = 1;
var allNumm = "";
for (i = 0; i < checkStri.length; i++) {
ch = checkStri.charAt(i);
for (j = 0; j < checkOKK.length; j++)
if (ch == checkOKK.charAt(j))
break;
if (j == checkOKK.length) {
allValidd = false;
break;
}
allNumm += ch;
}
if (!allValidd) {
alert("Escriba sólo dígitos en el campo \"Euros\".");
formulario.euros.focus();
return (false);
}
}
function peseta_euro()
{
peseEur=Math.round(checkStr/166.386);
alert(peseEur);
}
function euro_peseta()
{
euroPese=Math.round(checkStri*166.386);
alert(euroPese);
}
</script>
<body>
<form method = "get" onSubmit = "return validar(this)" action = "pregunta1.html" name="registro">
Pesetas: <input type="text" name="pesetas"><br>
<INPUT TYPE="button" value="Pesetas a Euros" onClick="peseta_euro()"><br>
Euros: <input type="text" name="euros"><br>
<INPUT TYPE="button" value="Euros a Pesetas" onClick="euro_peseta()"><br>
<input type="submit" value="Enviar datos" name="enviar">
</form>
</body>
</html>
  #2 (permalink)  
Antiguo 12/03/2006, 20:38
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Chequea este ejemplito.
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:26.