Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/04/2008, 00:45
AJDC
 
Fecha de Ingreso: agosto-2003
Mensajes: 324
Antigüedad: 20 años, 9 meses
Puntos: 1
No consigo detener el formulario

Saludos.
mirando las faqs de javascript, he logrado con dreamweaver, comprobar que los campos de mi formulario estén rellenos.
La validación la hace correctamente, pero me envía el formulario de todos modos.
A mi formulario le cambio el action, según que botón se pulse.
Os pongo el código...
Código HTML:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SIC .-</title>
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
<script language="JavaScript">
function envia(pag){
	document.envianoticia.action = pag
	document.envianoticia.submit()
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una dirección válida de correo.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' debe contener un número.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' debe contener un número entre  '+min+' y '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
    } if (errors) alert('Ocurrió el siguiente error:\n'+errors);
    document.MM_returnValue = (errors == '');
	return false;
} }
</script>
</head>
<body>

..... Para resumir directo al fomulario...

<form  name="envianoticia" id="envianoticia" onSubmit="MM_validateForm('titulo','','R','fechaemision','','R','franjahoraria','','R','contactocamara','','R','contactotelefono','','R','periodopublicacion','','R','resumen','','R');return document.MM_returnValue" >
							<table>
								<tr>
									<td>T&iacute;tulo:</td>
									<td><input type="text" name="titulo" size="50" maxlength="50" id="titulo" /></td>
								</tr>
								<tr>
									<td valign="top">Contenido:</td>
									<td valign="top"><textarea name="resumen" cols="50" rows="10" id="resumen"></textarea></td>
								</tr>
								<tr>
									<td>Fecha Grabaci&oacute;n:</td>
									<td><input type="text" name="fechaemision" size="50" maxlength="50" id="fechaemision" /></td>
								</tr>
								<tr>
									<td width="120">Hora Inicio:</td>
									<td><input type="text" name="franjahoraria" size="50" maxlength="50" id="franjahoraria" /></td>
								</tr>
								<tr>
									<td width="120">Contacto para el C&aacute;mara:</td>
									<td><input type="text" name="contactocamara" size="50" maxlength="50" id="contactocamara" /></td>
								</tr>
								<tr>
									<td width="120">Tel&eacute;fono Contacto:</td>
									<td><input type="text" name="contactotelefono" size="50" maxlength="50" id="contactotelefono" /></td>
								</tr>
								<tr>
									<td width="120">Fecha Emisi&oacute;n:</td>
									<td><input name="periodopublicacion" type="text" id="periodopublicacion" value= <?php
				$dia = date("j/n/Y"); 
				$mes = date("m");
				$anno = date("Y");
				if($mes == 12){
				$mes = 1;
				$anno = date("Y") + 1;
				}else{
				if((date("m") +1) < 10){
				$mes = "0" . (date("m") +1);
				}else{
				$mes = date("m") +1;
				}
				}
				echo "01/" . $mes . "/" . $anno;
				 ?>  size="50" maxlength="50" /></td>
								</tr>
							</table>
							<div align="right">
								<input name="bCancelar" type="button" id="bCancelar" onclick="javascript:history.back()" value="Cancelar"/>
								<input type="button" value="Guardar Borrador" onclick="envia('noticiaprociborrador.php')"/>
								<input type="submit" value="Publicar" onclick="envia('noticiaproci.php')" />
							</div>
						</form> 

Espero que podáis ayudarme.
Gracias