JavaScript - problema form+php

 
Vista:

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>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:problema form+php

Publicado por weirdmix (185 intervenciones) el 30/10/2007 17:54:43
cambia el tipo del input type=submit por type=button

saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por Luthien (4 intervenciones) el 30/10/2007 18:21:43
Gracias por tu respuesta pero ahora ni siquiera me responde el script de validacion de formulario.

saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por weirdmix (185 intervenciones) el 30/10/2007 23:58:16
cambia tu script de validacion por este:

<script language="javascript" type="text/javascript">
function Validar(){
//alert("entro");
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;
}

if (formulario.text.value == ""){
alert("Por favor ingrese la descripcion de la noticia");
formulario.text.focus();
return;
}

formulario.submit();
}
</script>

ahi me avisas...
saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por Luthien (4 intervenciones) el 31/10/2007 11:38:45
hola!
con esta modificacion aparece otra vez el mensaje si falta rellenar datos pero seguidamente envia los datos a la base de datos..

saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por Gonzalo (107 intervenciones) el 31/10/2007 11:43:53
Cambia los return; por return false;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por weirdmix (185 intervenciones) el 31/10/2007 15:01:24
si cambiaste el input type=submit por button ??????????
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por luthien (1 intervención) el 31/10/2007 16:15:35
Siii!!! ya funciona!! muchas gracias a todos.....

besos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema form+php

Publicado por jairo (1 intervención) el 22/03/2008 19:05:19
retira la linea

formulario.id.focus();

de todas las validaciones

maldito javascript....jajaja
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar