Ver Mensaje Individual
  #11 (permalink)  
Antiguo 28/09/2010, 22:42
scarlosc
 
Fecha de Ingreso: septiembre-2010
Mensajes: 2
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Formulario campos obligatorios

yo tento uno parecido ojala te sirva...
le das de nombre como quieras..

Cita:

<script language="Javascript" src="scriptt.js"></script>

<div class="entry">
<font size="3" face="Tahoma" color="#550000"><b>INSCRIBETE</b></font>
<p>

<form action="" name="form2" method="POST">

<table border="1" align="center" cellpadding="1" cellspacing="1">


<tr>
<td colspan="2" class="primeracolor">Datos Personales</td>
</tr>

<tr>
<td class="nombre" align="left">Nombres: </td>
<td class="caja"><input type="text" id="nombres" name="nombres" size="25" onkeyup="validarLetras(this.value,'nombres')"/></td>
</tr>

<tr>
<td class="nombre" align="left">Apellidos: </td>
<td class="caja"><input type="text" id="apellidos" name="apellidos" size="25" onkeyup="validarLetras(this.value,'apellidos')"/></td>
</tr>


<tr>

<td class="nombre" align="left">Direcci&oacute;n: </td>

<td class="caja"><input type="text" id="direccion" name="direccion" size="25" onkeyup="validardireccion(this.value,'direccion')" /></td>

</tr>

<tr>
<td class="nombre" align="left">E-mail: </td>
<td class="caja"><input type="text" id="mail" name="mail" size="25" onkeyup="validarMail(this.value,'mail')"/></td>
</tr>

<tr>
<td colspan="2" class="primeracolor">Datos de Inscripci&oacute;n</td>
</tr>


<tr>
<td class="nombre" align="left">N&uacute;mero de vaucher: </td>
<td class="caja"><input type="text" id="vaucher" name="vaucher" size="25" onkeyup="validarNumeros(this.value,'vaucher')"/></td>
</tr>

<tr>

<td class="nombre" align="left">Cantidad depositada: </td>

<td class="caja"><input type="text" id="deposito" name="deposito" size="25" onkeyup="validarNumerosDecimales(this.value,'depos ito')"/></td>
</tr>

<tr>
<td colspan="3" align="center"><input type="button" value="Confirmar" onclick="datosfaltantes()"/>&nbsp;&nbsp;<input type="reset" value="Cancelar" /></td>

</tr>

</table>

</form>


y este es el script....
le das de nombre. scriptt.

Cita:

function validarLetras(vartexto,campo) {
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " + "abcdefghijklmnopqrstuvwxyz" +
"\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\ u00d3\u00da\u00f1\u00d1";
//"á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","Ñ "
var checkStr = vartexto;

var allValid = true;

var ch;

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;

}
}

if (!allValid) {

alert("Error: \n \nA ingresado caracteres no validos en este campo.");

document.getElementById(campo).focus();
document.getElementById(campo).value="";

return (false);
}
}

function validardireccion(vartexto,campo) {

var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "-." + "0123456789";

var checkStr = vartexto;

var allValid = true;

var ch;


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;

}
}

if (!allValid) {

alert("Error: \n \nEscriba solo letras y digitos en este campo.");

document.getElementById(campo).focus();
document.getElementById(campo).value="";

return (false);
}
}

function validarMail(vartexto,campo) {

var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú" + "0123456789" + "_@.";

var checkStr = vartexto;

var allValid = true;

var ch;


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;

}
}

if (!allValid) {

alert("Error: \n \nSu mail no es correcto.");

document.getElementById(campo).focus();
document.getElementById(campo).value="";

return (false);
}
}


function validarNumeros(vartexto,campo) {

var checkOK = "0123456789";

var checkStr = vartexto;

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("Error: \n \nEscriba solo digitos en este campo.");

document.getElementById(campo).focus();
document.getElementById(campo).value="";

return (false);

}
}

function validarNumerosDecimales(vartexto,campo) {

var checkOK = "0123456789" + ".,";

var checkStr = vartexto;

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(vartexto < 0) {

allValid = false;
}

if (!allValid) {

alert("Error: \n \nLa cantidad ingresada es incorrecta.");

document.getElementById(campo).focus();
document.getElementById(campo).value="";

return (false);

}
}

function datosfaltantes() {

if(document.getElementById('nombres').value.length < 3) {

alert("Ingrese por lo menos 3 caracteres en el campo nombre");

return false;

}
else if(document.getElementById('apellidos').value.leng th < 3){

alert("Ingrese por lo menos 3 caracteres en el campo apellidos");

return false;

}
else if(document.getElementById('direccion').value.leng th < 4){

alert("Ingrese por lo menos 4 caracteres en el campo direccion");

return false;

}

else if(document.getElementById('mail').value.length < 4){

alert("La direccion de Correo no es Valida");

return false;

}

else if(document.getElementById('vaucher').value.length < 10){

alert("Ingrese por lo menos 10 digitos en el campo vaucher");

return false;

}

if(document.getElementById('deposito').value.lengt h == 0){

alert("Tiene que ingresar la cantidad depositada");

return false;

}



}