Ver Mensaje Individual
  #8 (permalink)  
Antiguo 15/09/2008, 22:14
Avatar de hector2c
hector2c
 
Fecha de Ingreso: noviembre-2007
Ubicación: Perú - Tacna
Mensajes: 979
Antigüedad: 16 años, 5 meses
Puntos: 25
Pregunta Respuesta: ayuda con formulario de contacto, remplazo de alert() en la validacion...

tal vezto te ayude:

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';
			if (nombre==""){
			  error_div_nombre.style.display = 'block';
				f.nombre.focus();
			  return false;
			}else{
			  error_div_nombre.style.display = 'none';
			}
			
			if (edad==""){
			  error_div_edad.style.display = 'block';
				f.edad.focus();
			  return false;
			}else{
			  error_div_edad.style.display = 'none';
			}
			
			return true;
						  
		}
  </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> 
suerte n_n
__________________
blog: hector2c.wordpress.com
email: [email protected]