Foros del Web » Programando para Internet » Javascript »

Ventana de confirmación antes de eliminar un registro

Estas en el tema de Ventana de confirmación antes de eliminar un registro en el foro de Javascript en Foros del Web. Hola una vez más, estoy intentando que al eliminar un registro de la base de datos salga antes una ventana de confirmación y hecho esto: ...
  #1 (permalink)  
Antiguo 26/04/2005, 11:22
 
Fecha de Ingreso: marzo-2004
Mensajes: 50
Antigüedad: 20 años
Puntos: 0
Sonrisa Ventana de confirmación antes de eliminar un registro

Hola una vez más,
estoy intentando que al eliminar un registro de la base de datos salga antes una ventana de confirmación y hecho esto:

echo "<B><FONT SIZE='1' COLOR='#666666' face='Verdana'><IMG SRC='imagenes/iconopapelera[1].png' WIDTH='41' HEIGHT='43' BORDER='0' ALT='' align='middle'>&nbsp;<A HREF='eliminarRegPartDest.php?nomUsuario=$nombreUs uario&laRef=$ref3&elname=$name&elapell=$apell' onclick='if(!confirm('Está seguro que desea eliminar el registro?'))return false;' class='mod'>Eliminar registro</A></font></B> ";

pero no funciona elimina el registro sin preguntar.

un saludo
  #2 (permalink)  
Antiguo 26/04/2005, 11:45
 
Fecha de Ingreso: marzo-2005
Mensajes: 163
Antigüedad: 19 años
Puntos: 0
seguramente te esta tomando antes el href al onClick. Le tendrias que poner al href un #, y en el onClick llamar a una funcion javaScript que tenga el confirm, luego de lo cual si acepto un window.location con la url que esta ahora en el href.
Pruebalo.
Saludos
  #3 (permalink)  
Antiguo 26/04/2005, 12:25
Avatar de isaacluz  
Fecha de Ingreso: marzo-2005
Mensajes: 180
Antigüedad: 19 años
Puntos: 0
onClick="javascript: return confirm('¿Estas seguro?');"
  #4 (permalink)  
Antiguo 26/04/2005, 12:34
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 1 mes
Puntos: 772
Hola isaacluz

Solo comentarte un pequeño detalle: no es necesario usar la palabra javascript:

onclick="return confirm('¿Estas seguro?');"

Saludos,
  #5 (permalink)  
Antiguo 26/04/2005, 13:17
Avatar de dwaks  
Fecha de Ingreso: agosto-2002
Ubicación: Panamá
Mensajes: 962
Antigüedad: 21 años, 7 meses
Puntos: 15
De acuerdo Toma este codigo que uso yo

Esto lo pones entre <head></head>

Código:
<script language="JavaScript">
function aviso(url){
if (!confirm("ALERTA!! va a proceder a eliminar este registro, si desea eliminarlo de click en ACEPTAR\n de lo contrario de click en CANCELAR.")) {
return false;
}
else {
document.location = url;
return true;
}
}
</script>
y lo usas asi:

Código:
<a href="javascript:;" onclick="aviso('borrar.php?uid=<?php echo $result["uid"]?>'); return false;">eliminar</a>
  #6 (permalink)  
Antiguo 27/04/2005, 04:15
 
Fecha de Ingreso: marzo-2004
Mensajes: 50
Antigüedad: 20 años
Puntos: 0
hola,
he probado tu código y me sale la ventana de confirmación, si cancelo la acción funciona bien, pero si voy a aceptar se redirecciona bien y me dice que ha borrado el registro pero en realidad no lo borra, he puesto esto:

<a href="javascript:;" onclick="confirmar('eliminarRegPartDest.php?laRef= <? $registro3['ref']?>'); return false;">Eliminar registro</a></font></B>

No recoge el valor de la variable, (en la barra de dirección aparece esto:http://localhost/eliminarRegPartDest.php?laRef=)

cuando lo tenía sin ventana de confirmación lo borraba sin problemas:
echo "<td>";
echo "<B><FONT SIZE='1' COLOR='#666666' face='Verdana'><IMG SRC='imagenes/iconopapelera[1].png' WIDTH='41' HEIGHT='43' BORDER='0' ALT='' align='middle'>&nbsp;<A HREF='eliminarRegPartc.php?nomUsuario=$nombreUsuar io&laRef=$Ref&elname=$name&elapell=$apell' class='mod'>Eliminar registro</A></font></B> ";
echo "</td>";
un saludo

Última edición por vanax; 27/04/2005 a las 04:27
  #7 (permalink)  
Antiguo 27/04/2005, 08:06
Avatar de dwaks  
Fecha de Ingreso: agosto-2002
Ubicación: Panamá
Mensajes: 962
Antigüedad: 21 años, 7 meses
Puntos: 15
El error es que no lo imprimes.

Esto esta mal:
<a href="javascript:;" onclick="confirmar('eliminarRegPartDest.php?laRef= <? $registro3['ref']?>'); return false;">Eliminar registro</a></font></B>

Esto esta bien:
<a href="javascript:;" onclick="confirmar('eliminarRegPartDest.php?laRef=<? echo $registro3['ref']?>'); return false;">Eliminar registro</a></font></B>

Saludos,
  #8 (permalink)  
Antiguo 27/04/2005, 08:37
 
Fecha de Ingreso: marzo-2004
Mensajes: 50
Antigüedad: 20 años
Puntos: 0
lo he probado como dices y sigue sin borrar el registro, he intentado de todo pero no hay manera.
un saludo
  #9 (permalink)  
Antiguo 27/04/2005, 08:40
Avatar de dwaks  
Fecha de Ingreso: agosto-2002
Ubicación: Panamá
Mensajes: 962
Antigüedad: 21 años, 7 meses
Puntos: 15
Si hay manera solo que no la vez aun, me gustaria que pusieras aqui el codigo desde la coneccion y consulta a la base de datos hasta la presentacion de los datos, alli vere como esta estructurado y puedo decirte con mas detalle que puede ser.

El error esta alli solo que no lo puedes ver.

Espero para ayudarte.

Saludos,
  #10 (permalink)  
Antiguo 27/04/2005, 08:42
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 1 mes
Puntos: 772
Hola a todos.

Creo que debería quedar así:

<a href="eliminarRegPartDest.php?laRef=<? echo $registro3['ref']?>" onclick="return confirm('¿Estás seguro?')">Borrar</a>

A ver si te funcina. Saludos,
  #11 (permalink)  
Antiguo 27/04/2005, 10:10
 
Fecha de Ingreso: marzo-2004
Mensajes: 50
Antigüedad: 20 años
Puntos: 0
Te escribo la parte del código que está implicada porque tengo un montón de lineas (585) :

<?php
include("conexion.php");
$conexBD=conectarse();

$sql3 = "SELECT id, ref,insertarFoto FROM anunciosDestacados where nomParticular='$nombreUsuario'";


$consulta3 = mysql_query($sql3) or die ("No se pudo ejecutar la consulta");
$num3=mysql_num_rows($consulta3);

echo "<tr>";
echo "<td colspan='3'>";
echo "<table width='90%' class='tb' border='0' align='center'><td align='center'>";



echo "<tr><td colspan='4'>&nbsp;</td></tr>";



echo "<tr><td colspan='4' bgcolor='#FFE5CC' align='center'><b><FONT SIZE='2' COLOR='#666666' face='Verdana'>&nbsp;&nbsp; Tienes&nbsp;&nbsp;".$num3."&nbsp;registros</FONT></td><td bgcolor='#ffffff' colspan='1'>&nbsp;</td></tr></table>";


echo "<tr><td colspan='3' height='142' width='100%'> ";

While ($registro3=mysql_fetch_assoc($consulta3)){


echo " <table width='90%' bgcolor='#ffffff' cellpadding='0' cellspacing='0' align='center' >";
echo "<tr>";
echo "<td colspan='4'>";
echo "<B><FONT SIZE='2' COLOR='#cc6633' face='Verdana'>&nbsp;&nbsp;&nbsp;Ref:".$registro3['ref']. "</FONT></B> <FONT SIZE='1' COLOR='#cc6633' face='Verdana'>&nbsp;</FONT>";

echo "&nbsp;&nbsp;<IMG SRC='imagenes/lineaVerde.jpg' WIDTH='800' BORDER='0' ALT='' align='texttop'></td></tr>";



$ref3=$registro3['ref'];

echo "<tr>";//<tr><td colspan='4'>&nbsp;&nbsp;&nbsp;

echo "<tr>";

echo "<td width='123'>";
echo "<a href='http://localhost/fotoNormalDest.php?id=".$registro3['id']. " '><img src=\"http://localhost/verDestacados.php?id=".$registro3['id']."\" hspace='10' vspace='10'></a>&nbsp;";
echo "</td>";
?>
<script language="JavaScript">
function confirmar(url){
if (!confirm("¿Está seguro de que desea eliminar el registro?")) {
return false;
}
else {
document.location= url;
return true;
}
}
</script>


<?

echo "<td><B><FONT SIZE='1' COLOR='#666666' face='Verdana'><IMG SRC='imagenes/iconosdatos[1].png' WIDTH='41' HEIGHT='43' BORDER='0' ALT='' align='middle'>&nbsp;<A HREF='camposModificacionParticularesDest.php?nomUs uario=$nombreUsuario&laRef=$ref3&elname=$name&elap ell=$apell' class='mod'>Modificar datos</A></font></B> ";
echo "</td>";
echo "<td>";
?>
<a href="javascript:;" onclick="confirmar('eliminarRegPartDest.php?laRef= <? $ref3?>'); return false;">Eliminar registro</a></font></B>

//tambien he probado esto

<!-- <a href="eliminarRegPartDest.php?laRef=<? echo $ref3?>" onclick="return confirm('¿Estás seguro?')">Borrar</a> -->


<?
echo "</td>";

echo "<td>";
echo "<B><FONT SIZE='1' COLOR='#666666' face='Verdana'><IMG SRC='imagenes/iconoimagen[1].png' WIDTH='41' HEIGHT='43' BORDER='0' ALT='' align='middle'>&nbsp;<A HREF='editarDestacadoPartic.php?nomUsuario=$nombre Usuario&laRef=$ref3' class='mod'>Ver propiedad</A></font></B> ";
echo "</td></tr><br>";

}

//

echo "</table></td></tr>";


Se redirecciona aeliminarRegPartDest.php:

<?php
include("conexion.php");
$conexBD=conectarse();

mysql_query( "OPTIMIZE TABLE anunciosDestacados") or die('Error: '.mysql_error());


$result=mysql_query("DELETE QUICK FROM anunciosDestacados WHERE ref='$laRef' and nomParticular='$nomUsuario' ",$conexBD);


//mysql_free_result($result);
mysql_query("OPTIMIZE TABLE anunciosDestacados");



mysql_close($conexBD);

echo "<html><head><title>Tipo de registro</title>
</head>";
echo "<body text='#000000'>";


echo " <table width='90%' border='0' bgcolor='#cc6633' align='center'><tr>";

echo "<tr><td>";
echo "El registro ha sido eliminado correctamente</td></tr>";
echo "<tr><td colspan='5' align='center'><A HREF='http://localhost/index.htm'><FONT SIZE='2' face='Verdana' >Volver a la página de inicio</FONT></A></td> </tr></table></body></html>";


?>
  #12 (permalink)  
Antiguo 27/04/2005, 10:22
Avatar de dwaks  
Fecha de Ingreso: agosto-2002
Ubicación: Panamá
Mensajes: 962
Antigüedad: 21 años, 7 meses
Puntos: 15
De acuerdo OK prueba este codigo que te mando que esta arreglado ciertos puntos.

Prueba con este codigo, es el tuyo con unos detalles mios.

Código PHP:
<?php 
include("conexion.php");
$conexBD=conectarse(); 

$sql3 "SELECT id, ref,insertarFoto FROM anunciosDestacados where nomParticular='$nombreUsuario'"


$consulta3 mysql_query($sql3,$conexBD) or die ("No se pudo ejecutar la consulta"); 
$num3=mysql_num_rows($consulta3); 

echo 
"<tr>";
echo 
"<td colspan='3'>";
echo 
"<table width='90%' class='tb' border='0' align='center'><td align='center'>";



echo 
"<tr><td colspan='4'>&nbsp;</td></tr>";



echo 
"<tr><td colspan='4' bgcolor='#FFE5CC' align='center'><b><FONT SIZE='2' COLOR='#666666' face='Verdana'>&nbsp;&nbsp; Tienes&nbsp;&nbsp;".$num3."&nbsp;registros</FONT></td><td bgcolor='#ffffff' colspan='1'>&nbsp;</td></tr></table>";


echo 
"<tr><td colspan='3' height='142' width='100%'> ";

while(
$registro3=mysql_fetch_array($consulta3)){


echo 
" <table width='90%' bgcolor='#ffffff' cellpadding='0' cellspacing='0' align='center' >";
echo 
"<tr>";
echo 
"<td colspan='4'>";
echo 
"<B><FONT SIZE='2' COLOR='#cc6633' face='Verdana'>&nbsp;&nbsp;&nbsp;Ref:".$registro3["ref"]. "</FONT></B> <FONT SIZE='1' COLOR='#cc6633' face='Verdana'>&nbsp;</FONT>"

echo 
"&nbsp;&nbsp;<IMG SRC='imagenes/lineaVerde.jpg' WIDTH='800' BORDER='0' ALT='' align='texttop'></td></tr>";



$ref3 $registro3["ref"];

echo 
"<tr>";//<tr><td colspan='4'>&nbsp;&nbsp;&nbsp;

echo "<tr>";

echo 
"<td width='123'>";
echo 
"<a href='http://localhost/fotoNormalDest.php?id=".$registro3["id"]. " '><img src=\"http://localhost/verDestacados.php?id=".$registro3["id"]."\" hspace='10' vspace='10'></a>&nbsp;"
echo 
"</td>";
?>
<script language="JavaScript">
function confirmar(url){
if (!confirm("¿Está seguro de que desea eliminar el registro?")) {
return false;
}
else {
document.location= url;
return true;
}
}
</script>


<?

echo "<td><B><FONT SIZE='1' COLOR='#666666' face='Verdana'><IMG SRC='imagenes/iconosdatos[1].png' WIDTH='41' HEIGHT='43' BORDER='0' ALT='' align='middle'>&nbsp;<A HREF='camposModificacionParticularesDest.php?nomUs uario=$nombreUsuario&laRef=$ref3&elname=$name&elapell=$apell' class='mod'>Modificar datos</A></font></B> ";
echo 
"</td>";
echo 
"<td>";
?>
<a href="javascript:;" onclick="confirmar('eliminarRegPartDest.php?laRef=<?php echo $ref3?>'); return false;">Eliminar registro</a></font></B> 

<?
echo "</td>";

echo 
"<td>";
echo 
"<B><FONT SIZE='1' COLOR='#666666' face='Verdana'><IMG SRC='imagenes/iconoimagen[1].png' WIDTH='41' HEIGHT='43' BORDER='0' ALT='' align='middle'>&nbsp;<A HREF='editarDestacadoPartic.php?nomUsuario=$nombre Usuario&laRef=$ref3' class='mod'>Ver propiedad</A></font></B> ";
echo 
"</td></tr><br>";

}

//

echo "</table></td></tr>";
?>
  #13 (permalink)  
Antiguo 28/04/2005, 12:04
 
Fecha de Ingreso: marzo-2004
Mensajes: 50
Antigüedad: 20 años
Puntos: 0
Por fin funciona!!
el problema estaba aquí:
$result=mysql_query("DELETE QUICK FROM anunciosDestacados WHERE ref='$laRef' and nomParticular='$nomUsuario' ",$conexBD);

No le estaba pasando la variable '$nomUsuario', tenía que quedar así:

<a href="javascript:;" onclick="confirmar('eliminarRegPartDest.php?laRef= <?echo $ref3;?>&nombre=<?echo $nombre3;?>'); return false;">Eliminar registro</a></font></B>
Gracias por tu ayuda,
un saludo
  #14 (permalink)  
Antiguo 03/09/2011, 14:43
 
Fecha de Ingreso: septiembre-2011
Mensajes: 5
Antigüedad: 12 años, 6 meses
Puntos: 0
Respuesta: Ventana de confirmación antes de eliminar un registro

echenme a mi tambien una mano p:

les dejo mi codigo

<?php
$connect=mysql_connect("localhost","root","");
$db=mysql_select_db('carrito');
$consulta=mysql_query("SELECT *FROM productos ");
?>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
.Estilo5 {font-size: 12px; color: #FFFFFF; }
.Estilo6 {color: #FFFFFF}
.Estilo12 {
color: #FFFFFF;
font-size: 16px;
font-weight: bold;
}
.Estilo13 {color: #FFFFFF; font-weight: bold; }
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: none;
color: #FFFFFF;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
-->
</style>
<div align="center" class="Estilo13">LISTADO DE PRODUCTOS </div>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="244" scope="col"><strong><span class="Estilo6"><a href="administrativo/administracion.php">Men&uacute;</a></span></strong></th>
<th width="375" valign="top" scope="col"><div align="right"></div></th>
<th width="222" scope="col"><div align="left">
<form id="form1" name="form1" method="post" action="ver_borrar_modifi2.php">
<label></label>
<input name="buscar" type="text" id="busqueda" />
<input type="submit" name="Submit" value="Buscar" />
</form>
</div></th>
</tr>
</table>

<th colspan="6" scope="col"><table width="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th scope="col"><table width="801" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="119" bgcolor="#002b5e"><div align="center"><strong><span class="Estilo6">Producto</span></strong></div></td>
<td width="119" bgcolor="#002B5E"><div align="center" class="Estilo6"><strong>Imagen</strong></div></td>
<td width="112" bgcolor="#002b5e"><div align="center"><strong><span class="Estilo6">Marca</span></strong></div></td>
<td width="141" bgcolor="#002b5e"><div align="center" class="Estilo12">Descripci&oacute;n</div></td>
<td width="81" bgcolor="#002b5e"><div align="center"><strong><span class="Estilo6">Precio</span></strong></div></td>
<td width="117" bgcolor="#002b5e"><div align="center"><strong><span class="Estilo6">Modificar</span></strong></div></td>
<td width="96" bgcolor="#002b5e"><div align="center"><strong><span class="Estilo6">Eliminar</span></strong></div></td>
</tr>
</table>
<?php

while($mostrar=mysql_fetch_array($consulta))
{
$id=$mostrar['id'];
$nombre=$mostrar['nombre'];
$imagen=$mostrar['imagen'];

$eliminar="<a href='javascript:mi_alerta()'>Eliminar</a>";




?>
<table width="800" border="1" align="center" cellspacing="0">
<tr>
<th width="116" bgcolor="#001837" scope="col">&nbsp;<span class="Estilo5"><?php echo $id ?></span></th>
<th width="116" height="23" bgcolor="#FFFFFF" scope="col"><?php echo '<img src="'.$mostrar['imagen'].'"width="100"/>' ?>&nbsp;
<th width="110" bgcolor="#001837" scope="col">&nbsp;<span class="Estilo5"><?php echo $nombre ?></span></th>
<th width="140" bgcolor="#001837" scope="col">&nbsp;<span class="Estilo5"></span></th>
<th width="78" bgcolor="#001837" scope="col">&nbsp;<span class="Estilo5"></span></th>
<th width="116" bgcolor="#001837" scope="col">&nbsp;</th>
<th width="94" bgcolor="#001837" scope="col">&nbsp;<?php echo $eliminar ?> </th>
</tr>
<?php

}
?>
</table></th>
</tr>
</table></th>

<head>
<script language="Javascript">
function mi_alerta()
{
confirmar=confirm("Esta Usted seguro que desea eliminar este producto");

if (confirmar)
{
location.href='confirmar_eliminacion.php?imagen=$i magen & id_sub=$id_sub';

}


}
</script>
</head>
  #15 (permalink)  
Antiguo 03/09/2011, 14:44
 
Fecha de Ingreso: septiembre-2011
Mensajes: 5
Antigüedad: 12 años, 6 meses
Puntos: 0
Respuesta: Ventana de confirmación antes de eliminar un registro

es el mismo tema y la misma necesidad
  #16 (permalink)  
Antiguo 04/09/2011, 04:37
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 10 meses
Puntos: 834
Respuesta: Ventana de confirmación antes de eliminar un registro

raulfonck24, mejor plantea tu problema en un nuevo mensaje, usando la herramienta highlight para mostrar código. Te sugiero que sólo coloques el código que aparece en el navegador al usar la opción ver código fuente (muchos aquí no conocen el lenguaje php).
Dicho esto, cerramos este hilo por antiguo.

Última edición por Panino5001; 04/09/2011 a las 04:54
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 18:17.