Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/12/2004, 00:33
kepawe
 
Fecha de Ingreso: agosto-2004
Mensajes: 157
Antigüedad: 20 años, 6 meses
Puntos: 5
Hola lorecasas

Son muchas campos para comprobar . Creo que seria buena idea marcar los campos obligatorios con un color. En el ejemplo que te envio he puesto los bordes de color rojo para los campos obligatorio, y los no obligatorios en negro.


<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
.obligatorio{
border:1px solid red;
}
.noObligatorio{
border:1px solid black;
}
-->
</style>

<script language=JavaScript type=text/javascript>
<!--


String.prototype.itsWhitespace = function(){
return this.search(/\S/g) == -1 ? true : false

}

var msk_txt = /txt\d/

function check_txt(current_form){
// esta variable cuenta los campos vacios
var its_ok = 0
for(var ctr = 0; ctr < current_form.length; ctr++){
// coprobamos que el campo es obligatorio
if(msk_txt.test(current_form[ctr].name)){
// comprobamos que no este vacio
if(current_form[ctr].value.itsWhitespace()){
// esta vacio, marcamos el campo en rojo
current_form[ctr].style.border = "1px solid red"

its_ok++
}
else{
// esta
current_form[ctr].style.border = "1px solid black"
}

}

}
if(its_ok == 0){
// Enviamos el formulario
current_form.submit()
}
else{

alert("Por favor rellene los campos rojos")
}
}

//-->
</script>

</head>
<body>
<form action="formulario.php" method="post" name="form1" onsubmit="return false">
<input class="obligatorio" type="text" name="txt01" >
<input class="obligatorio" type="text" name="txt02" >
<input class="obligatorio" type="text" name="txt03" ><br>
<input class="noObligatorio" type="text" name="txtno"> Campo no obligatorio
<input type="button" value="Enviar" onclick = "check_txt(this.form)">
</form>
</body>
</html>


Espero que te sea util.

Un saludo