problema form+php
Publicado por Luthien (4 intervenciones) el 30/10/2007 15:51:57
hola a todos..
estoy con una validacion de un formulario, y me esta dado el problema de que aunque valida los campos, envia el formulario igual. si me podeis ayudar, no encuentro el error por ningun lado...
gracias!!
<html>
<head>
<script>
function Validar(form){
if (formulario.id.value == "")
{ alert("Por favor ingrese el codigo de la noticia"); formulario.id.focus(); return; }
if (formulario.titulo.value == "")
{ alert("Por favor ingrese el titulo de la noticia"); formulario.titulo.focus(); return; }
formulario.submit();
}
if (formulario.texto.value == "")
{ alert("Por favor ingrese la descripcion de la noticia"); formulario.texto.focus(); return; }
formulario.submit();
}
</script>
<style type="text/css">
<!--
.Estilo10 {font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; }
.Estilo13 {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
}
-->
</style>
</head>
<body>
<FORM name="formulario" ACTION="insertarnoticia.php" method="post">
<TABLE>
<TR>
<TD height="44" colspan="4" bgcolor="#006699"><span class="Estilo13">Crear Notícia </span></TD>
</TR> <TR>
<TD><span class="Estilo10">Id:</span></TD>
<TD width="659" colspan="3"><span class="Estilo10">
<INPUT NAME="id" TYPE="text" SIZE="20" MAXLENGTH="30">
</span></TD>
</TR>
<TR>
<TD><span class="Estilo10">Titulo Notícia:</span></TD>
<TD colspan="3"><span class="Estilo10">
<INPUT NAME="titulo" TYPE="text" SIZE="20" MAXLENGTH="30">
</span></TD>
</TR>
<TR>
<TD valign="top"><span class="Estilo10">Descripción</span></TD>
<TD colspan="3"><span class="Estilo10">
<label>
<textarea name="text" cols="75" rows="15"></textarea>
</label>
</span></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" name="envio" onClick="Validar(this.form)" VALUE="Grabar" >
</FORM>
<hr>
</table>
estoy con una validacion de un formulario, y me esta dado el problema de que aunque valida los campos, envia el formulario igual. si me podeis ayudar, no encuentro el error por ningun lado...
gracias!!
<html>
<head>
<script>
function Validar(form){
if (formulario.id.value == "")
{ alert("Por favor ingrese el codigo de la noticia"); formulario.id.focus(); return; }
if (formulario.titulo.value == "")
{ alert("Por favor ingrese el titulo de la noticia"); formulario.titulo.focus(); return; }
formulario.submit();
}
if (formulario.texto.value == "")
{ alert("Por favor ingrese la descripcion de la noticia"); formulario.texto.focus(); return; }
formulario.submit();
}
</script>
<style type="text/css">
<!--
.Estilo10 {font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; }
.Estilo13 {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
}
-->
</style>
</head>
<body>
<FORM name="formulario" ACTION="insertarnoticia.php" method="post">
<TABLE>
<TR>
<TD height="44" colspan="4" bgcolor="#006699"><span class="Estilo13">Crear Notícia </span></TD>
</TR> <TR>
<TD><span class="Estilo10">Id:</span></TD>
<TD width="659" colspan="3"><span class="Estilo10">
<INPUT NAME="id" TYPE="text" SIZE="20" MAXLENGTH="30">
</span></TD>
</TR>
<TR>
<TD><span class="Estilo10">Titulo Notícia:</span></TD>
<TD colspan="3"><span class="Estilo10">
<INPUT NAME="titulo" TYPE="text" SIZE="20" MAXLENGTH="30">
</span></TD>
</TR>
<TR>
<TD valign="top"><span class="Estilo10">Descripción</span></TD>
<TD colspan="3"><span class="Estilo10">
<label>
<textarea name="text" cols="75" rows="15"></textarea>
</label>
</span></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" name="envio" onClick="Validar(this.form)" VALUE="Grabar" >
</FORM>
<hr>
</table>
Valora esta pregunta


0