Ver Mensaje Individual
  #34 (permalink)  
Antiguo 18/09/2008, 17:23
binagol
 
Fecha de Ingreso: agosto-2008
Ubicación: Buenos Aires
Mensajes: 247
Antigüedad: 16 años, 7 meses
Puntos: 6
Respuesta: ayuda con formulario de contacto, remplazo de alert() en la validacion...

perdon por la demora en contestar....

ok, corregi lo que mensionaste, pero sigue sin funcionar.

quedo asi:

Código HTML:
<html>
  <script language="javascript" type="text/javascript">
	
	  function validar(f){
		    nombre = f.nombre.value;
			edad = f.edad.value;
			error_div_nombre = document.getElementById('div_nombre');
			error_div_edad = document.getElementById('div_edad');
			document.getElementById('div_envio').style.display = 'none';
			showdivs = new Array();
			fallo_validar = false;

  		    if (nombre==""){
  			  showdivs[showdivs.length] = 'div_nombre';
			  f.nombre.focus(); 
			  fallo_validar = true;
			}else{
			error_div_nombre.style.display = 'none';
			}
			
			if (edad==""){
   			  showdivs[showdivs.length] = 'div_edad';
			  f.edad.focus(); 
			  fallo_validar = true;		 
			}else{
			error_div_edad.style.display = 'none';
			}
	
			if (fallo_validar==true)
			  setTimeout("contar=0;mostrar()", 1000);
			  return false;
			else
			  return true;
						  
		}
		
	function mostrar() {
        document.getElementById(showdivs[contar]).style.display = "block";
        contar += 1;
        if (contar < showdivs.length) { setTimeout("mostrar()", 1000) }
    }
		
  </script>
  <style type="text/css">
	  body, input, td {
		  font-family: Tahoma;
			font-size: 11px;
			color: #666;
		}
		
	  .error {
		  background-color:#f66;
			color: #fff;
			padding: 10px;
			display: none;
		}
		
		.envio {
		  background-color:#FFFFDF;
			padding: 10px;
		}
  </style>
  <body>
    <form action="<?=$PHP_SELF?>" method="post" name="formulario" id="formulario" onSubmit="return validar(this);">
      <table>
        <tbody>
          <tr>
            <td>nombre</td>
            <td><input name="nombre" type="text" id="nombre" /></td>
          </tr>
          <tr>
            <td>edad</td>
            <td><input name="edad" type="text" id="edad" /></td>
          </tr>
        </tbody>
        <tfoot>
          <tr>
            <td colspan="2"><input name="enviar" type="submit" id="enviar" value="Enviar" /></td>
          </tr>
        </tfoot>
      </table>
	  </form>
    <div id="div_nombre" class="error">Por favor ingrese su nombre</div>
    <div id="div_edad" class="error">Por favor ingrese su edad</div>
    <div id="div_envio" class="envio">
    <?php
		  if (isset($_POST['enviar'])){
			  echo "<strong>nombre: </strong>".$_POST['nombre']."<br>";
				echo "<strong>edad: </strong>".$_POST['edad'];
			}
		?>
    </div>
  </body>
</html>