Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/12/2008, 19:39
fiorella_liz
 
Fecha de Ingreso: noviembre-2008
Ubicación: lima
Mensajes: 148
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: Si no rellena campo que de un aviso

hola drdilusion.
aqui te dejo tu codigo modificado. te explico.
le añadi un evento al boton que envia el formulario, este evento llama a la funcion javascript evalua() y esta revisa si la caja de texto y l text area estan vacios, si es así pues te emite una alerta.

aunque se puede hacer tbn con php, pero la prsentacion queda mas limpia con javascript.

suerte y eespero qu ete sirva bye.
Código PHP:
<html> 
<head>
<script type="text/javascript">
function evaluar()
{
  if(document.all.nombre.value=='')
  {
     alert('Ingrese su nombre por favor');
     document.all.nombre.focus();
     return false;
  }
  
  if(document.all.comen.value=='')
  {
     alert('Ingrese comentario por favor');
     document.all.comen.focus();
     return false;
  }
  return true;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> 
<body topmargin="0">

<FORM ACTION="procesar.php" name="form" id="form">
<TABLE width="563" border="0">
<TR> 
<TD colspan="2"><strong>Nombre</strong>/<em>Name</em></TD>
<TD>&nbsp;</TD>
<TD width="245"><strong>Comentario</strong>/<em>Comment</em></TD>
<TD width="245">&nbsp;</TD>
</TR>
<TR> 
<TD colspan="2"><input type="text" name="nombre" size="20" maxlength="60"> 
</TD>
<TD width="10">&nbsp;</TD>
<TD width="245"><textarea name="comen" cols="35" id="textarea"></textarea> 
</TD>
<TD width="372">&nbsp; </TD>
</TR>
<TR> 
<TD width="59">&nbsp;</TD>
<TD width="59" colspan="-1">&nbsp;</TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE> 
<INPUT TYPE="submit" NAME="accion" VALUE="Añadirme a la lista / Add to the list" onClick="return evaluar()">
</FORM> 
<hr> 


<?php 
include("conex.php"); 
$link=Conectarse(); 
$result=mysql_query("select * from prueba ORDER BY n DESC",$link);
// $result=mysql_query("select * from prueba",$link); 
?> 

<TABLE BORDER=1 CELLPADDING=1 CELLSPACING=1>
<TR>
<TD class="tf">&nbsp;</TD>
<TD align="center" class="tf">&nbsp;<B>Nombre/</B><em>Name</em></TD>
<TD align="center" class="tf">&nbsp;<B>Comentario/</B><em>Comment</em>&nbsp;</TD>
<TD align="center" class="tf">&nbsp;<B>Pais/</B><em>Country</em>&nbsp;</TD>
<TD align="center" class="tf">&nbsp;<B>Fecha/</B><em>Date</em>&nbsp;</TD>
</TR> 
<?php 

while($row mysql_fetch_array($result)) { 
printf("<tr><td>&nbsp;%s</td><td>&nbsp;%s</td> <td>&nbsp;%s&nbsp;</td><td>&nbsp;%s&nbsp;</td><td>&nbsp;%s&nbsp;</td></tr>"$row["N"], $row["Nombre"], $row["comen"], $row["pais"], $row["fecha"]); 


mysql_free_result($result); 
mysql_close($link); 
?> 

</table> 
</body> 
</html>