les dejo el codigo que llevo hasta el momento:
Javascript
Código:
<script>
function validarEntero(valor){
valor = parseInt(valor)
//Comprobacion del valor numerico
if (isNaN(valor)) {
//Valor NO numerico
return ""
}else{
//En caso de ser numerico, lo asigno nada mas
return valor
}
}
function valida_envia(){
//validando el nombre
if (document.fvalida.nombre.value.length==0){
alert("Tiene que escribir su nombre")
document.fvalida.nombre.focus()
return 0;
}
//validando la edad.
edad = document.fvalida.edad.value
edad = validarEntero(edad)
document.fvalida.edad.value=edad
if (edad==""){
alert("Tiene que introducir un número entero en su edad.")
document.fvalida.edad.focus()
return 0;
}
//valido el hobbie
if (document.fvalida.hobbie.selectedIndex==0){
alert("Debe seleccionar al menos un hobbie.")
document.fvalida.hobbie.focus()
return 0;
}
//el formulario se envia
alert("Muchas gracias por enviar el formulario");
document.fvalida.submit();
}
</script>
Formulario:
Código:
<form name="fvalida"> <table> <tr> <td>Nombre: </td> <td><input type="text" name="nombre" size="30" maxlength="100"/></td> </tr> <tr> <td>Email: </td> <td><input type="text" name="email" size="30" maxlength="20"/></td> </tr> <tr> <td>Edad: </td> <td><input type="text" name="edad" size="3" maxlength="2"/></td> </tr> <tr> <td>Hobbie:</td> <td> <select name="hobbie"> <option value="Elegir">Elegir <option value="Internet">Internet <option value="Deporte">Deporte <option value="Lectura">Lectura </select> </td> </tr> <tr> <td colspan="2" align="center"><input type="button" value="Enviar" onclick="valida_envia()"/></td> </tr> </table> </form>

