Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/09/2004, 16:20
ciberpata
 
Fecha de Ingreso: junio-2003
Ubicación: Santiago de Compostela
Mensajes: 603
Antigüedad: 21 años, 9 meses
Puntos: 0
Hola JavierB, bueno despues de algun tiempo intentando que funcionase el código al que me remitiste, ya consigo que me valide si el campo pedidotalla está vacio. El problema es que cuando pulso sobre el boton aceptar del "alert" el formulario sigue su proceso y pasa al carrito con el campo igualmente vacio.
Lo que necesito es que al pulsar sobre el boton aceptar del "alert" se interrumpa el funcionamiento del form y se quede esperando que el usuario complete el campo pedidotalla. Es decir que no pase al carrito.
Por otro lado tengo otra pregunta.
Si lo que necesitase fuese validar campos que no tuviesen el mismo nombre de de campo, es decir que no fuesen como en el ejemplo, (elemento0, elemento1, elemento2 y asi sucesivamente) que modificaciones tendría que llevar a cabo en el script.
Siento estas preguntas pero no tengo idea de javascript.

Código:
 
<SCRIPT LANGUAGE="JavaScript">
<!--
function AbrirVentana (theURL, winName, features)
{
window.open (theURL, winName, features);
return false
}
-->
</SCRIPT>  

<script language="JavaScript"> 
   function noVacio() { 
	var i; 
	var n = parseInt(document.frm.cantidad.value); 
	var bError = false; 

	for (i = 0; i < n; i++){ 
	 bError = bError || (eval("document.frm.pedidotalla" + ".value == ''")); 
	 if (bError){ 
	  alert("Debe introducir una talla para poder realizar el pedido"); 
	  eval("document.frm.pedidotalla" + ".focus()"); 
	  break; 
	 } 
	} 
   } 

  </script> 
  
  <%
  ' Recupera el identificador de producto
  IDProducto = TRIM( Request( "idp" ) )
  
  ' Abre la conexión a la base de datos
  Set Conexion = Server.CreateObject( "ADODB.Connection" )
  Conexion.Open "DSN=clubviajesoferta.com.amancio"
  
  ' Recupera la información del producto
  sqlString = "SELECT * FROM Productos WHERE IdentificadorProducto=" & IDProducto
  Set RS = Server.CreateObject( "ADODB.Recordset" )
  RS.ActiveConnection = Conexion
  RS.Open sqlString
  
  ' Carga la categoría activa
  cat = RS("familiaproducto")
  %>
  <html>
  <head>
  <title>Amancio Deportes</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
  <body  scroll="auto" link="#ff4040" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" vtext="lightred">
  <center>
 
  <table width=440 border=0 align="left" cellpadding=0
   cellspacing=0>
  <tr>
	  <td align=right valign="bottom">
	  <a href="../carritocompras/session_carrito.asp">Carrito de compras</a></td>
  </tr>
  </table>
 
 
  <br>
  <table width=130 border=0 align="left"
   cellpadding=0 cellspacing=0 bgcolor="#ffffff">
	<tr>
	  <td width="130" valign="top"><table width="130" border=0 cellpadding=0 cellspacing=0>
		  <tr>
			<td width="130" valign="bottom"><img src="../images/iconos/buscar_texto.gif" width="130" height="20" vspace=0 border=0></td>
		  </tr>
		  <tr>
			<td><table width="130" cellpadding=4 cellspacing=0
	   bgcolor="lightyellow" border=1>
				<tr>
				  <td width="130"><form method="post" action="../carritocompras/buscar.asp">
					  <input name="buscar" size="10" maxlength="10">
					  <input name="image" type="image" src="../images/iconobuscar.gif" alt="Pulse aqu&iacute; para buscar un producto en nuestra tienda" align="middle" width="20" height="20" border="0">
				  </form></td>
				</tr>
			</table></td>
		  </tr>
		  <tr>
			<td>&nbsp;</td>
		  </tr>
		  <tr>
			<td valign="bottom"><img src="../images/iconos/deporte_buscar.gif" width="130" height="20" vspace=0 border=0></td>
		  </tr>
		  <tr>
			<td><table width="130" cellpadding=4 cellspacing=0
	   bgcolor="lightyellow" border=1>
				<tr>
				  <td width="130"><font size="3"><b>
					<!-- #INCLUDE file="../carritocompras/lista_cat.asp" --></td>
				</tr>
			</table></td>
		  </tr>
	  </table></td>
	</tr>
  </table>
  <table width="309"  border="0" align="left">
	
	<tr>
	  <td width="209" align="left"><% IF RS( "ImagenProducto" ) <> "?????" THEN %>
   <a href="producto.asp"
  onClick="return AbrirVentana('producto_grande.asp?identificadorproducto=<%=RS("identificadorproducto")%>', '', 'scrollbars=no, top=112, left=165, width=<%=rs("Imagenproductoancho")%>, height=<%=rs("Imagenproductoalto")%>>, resizable=0')" shape="rect" > 
	   <img src="<%=RS( "ImagenProducto" )%>" alt="Ver Producto Ampliado" width="<%=rs("Imagenproductoancho")/2%>" height="<%=rs("Imagenproductoalto")/2%>" border="0"></a> 
	<% END IF %></td>
	  <td width="90" align="left"><% IF RS( "ImagenProducto1" ) <> "?????" THEN %>
		<a href="producto.asp"
  onClick="return AbrirVentana('producto_grande.asp?identificadorproducto=<%=RS("identificadorproducto")%>', '', 'scrollbars=no, top=112, left=475, width=<%=rs("Imagenproducto1ancho")%>, height=<%=rs("Imagenproducto1alto")%>>, resizable=0')" shape="rect" > 
	   <img src="<%=RS( "ImagenProducto1" )%>" alt="Ver Producto Ampliado" width="<%=rs("Imagenproducto1ancho")/2%>" height="<%=rs("Imagenproducto1alto")/2%>" border="0"></a> 
		<% END IF %></td>
	</tr>
 <tr>
	  <td colspan="2" align="left"><p> <font color="#FB4C50" size="3" face="Arial"><b> <%=RS( "NombreProducto" )%> </b> </font>
		<p> <font color="#000066">Tallas disponibles: <%=rs("tallajeproducto")%></font> <br>
		  <font color="#000066">Colores disponibles: <%=rs("colorproducto")%><br>
		  Precio: <strong><%=RS( "precioproducto" )%> &euro;
		  </strong> </font>
		<p><font color="#000066"><%=RS( "Descripcionproducto" )%>
		</font>		  
		<form action="../carritocompras/session_carrito.asp" method="post" name="frm" id="frm">
		  <p><font color="#000066">Pedir talla:
			  <input name="pedidotalla" type="text" id="pedidotalla" size="20" maxlength="20">
			  <br>
			Pedir color: 
		  <input name="pedidocolor" type="text" id="pedidocolor" size="30" maxlength="100"></font>
			<input name="idp" type="hidden" value="<%=RS( "IdentificadorProducto" )%>">
			<input name="nombreproducto" type="hidden" value="<%=RS( "nombreproducto" )%>">
			<input name="precioproducto" type="hidden" value="<%=RS( "precioproducto" )%>">
   <input type="hidden" name="cantidad" value="1"> 
			<br>
			
		  </p>
		  <p align="center"><input type="submit" value="Agregar al carrito" onclick="noVacio()">
		  </p>
		</form>
		<p><font color="#000066"><%=RS( "DescripcionProducto" )%></font></p>
	  </td>
 </tr>
  </table>
  </center>
  </body>
  </html>