Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/05/2002, 14:20
sonneman
 
Fecha de Ingreso: mayo-2002
Mensajes: 299
Antigüedad: 22 años, 10 meses
Puntos: 0
Re: Funcion Para Validar Campos Vacios De Un Form

mira este es el script ya solo te queda agregar en el form action onsubmit="return validar(this)"
y tu boton:
input onclick=formValid(); type="submit" name="enviar"value="GUARDAR"&g t;</td>

<SCRIPT language=JavaScript>

<!--- oculta el script para navegadores antiguos

function checkElement(el_obj)
{
var result = true;
if(el_obj.options==null) {
if(el_obj.value=="") result = false;
} else if(el_obj.selectedIndex==0) result = false;
return result;
}

function formValid()
{

var i = 0;
j = 0;
StringToView = "";
IsValidated = true;
NeedToCheckElement = true;
DontCheck = new Array("Comments");

for(i=0; i<document.forms[0].elements.length; i++) {
if(DontCheck.length==0) {
if(checkElement(document.forms[0].elements[I])==false) IsValidated=false;
} else {
NeedToCheckElement = true;
for(j=0; j<DontCheck.length; j++) if(document.forms[0].elements[i].name==DontCheck[j]) NeedToCheckElement = false;
if(NeedToCheckElement) {
if(!checkElement(document.forms[0].elements[i])) IsValidated=false;
}
}
}


if(IsValidated==false)
{
alert('Debe rellenar el formulario por completo. Todos los campos son requeridos.');
return false;
} else {
for(i=0; i<document.forms[0].elements.length; i++)
if(document.forms[0].elements[i].type=="text") StringToView=StringToView + document.forms[0].elements[i].name + ": " + document.forms[0].elements.value + "\n\n";
if(confirm(StringToView + "\n?Es esta información correcta?")) document.forms[0].submit();
return true;
}
}

// end hiding from old browsers -->
</SCRIPT>





espero y te sirva