Foros del Web » Programando para Internet » Javascript »

Eliminar un dato en un select

Estas en el tema de Eliminar un dato en un select en el foro de Javascript en Foros del Web. Buenos dias queria saber si yo tengo cargado un select con unos datos de mi base de datos y desea agregar un boton para eliminar ...
  #1 (permalink)  
Antiguo 28/07/2009, 08:14
 
Fecha de Ingreso: julio-2009
Mensajes: 7
Antigüedad: 14 años, 9 meses
Puntos: 0
Mensaje Eliminar un dato en un select

Buenos dias queria saber si yo tengo cargado un select con unos datos de mi base de datos y desea agregar un boton para eliminar ese elemento tanto del select como de la base de dato como podria hacer alguien tiene un codigo de ejemplo, de antemano les doy las gracias.
  #2 (permalink)  
Antiguo 28/07/2009, 08:22
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Eliminar un dato en un select

Tendrías que usar AJAX, para enviar la consulta al servidor y eliminar el elemento y luego usar Javascript para eliminar el elemento del select (eso si lo quieres hacer sin refrescar la pagina).

Si lo quieres hacer enviando la pagina solamente pon el select y agrega un submit al servidor y borras la opción de la base de datos, al volver a dibujar el select ya no debería aparecer si lo haces desde datos de la BDD.

Saludos.
  #3 (permalink)  
Antiguo 28/07/2009, 08:42
 
Fecha de Ingreso: julio-2009
Mensajes: 7
Antigüedad: 14 años, 9 meses
Puntos: 0
Mensaje Respuesta: Eliminar un dato en un select

te comprendo perfectamente te voy a poner mi codigo porque no me esta funcionado porque ya lo habia hecho de esa manera pero no se que error me esta sucediendo ya que tengo dos submit mas en ese formulario

<script type="text/javascript">
function volcarSelects(emisor, receptor){
// Accedemos a los 2 selects
emisor = document.getElementById(emisor);
receptor = document.getElementById(receptor);

// Obtenemos algunos datos necesarios
posicion = receptor.options.length;
selecionado = emisor.selectedIndex;

if(selecionado != -1) {

volcado = emisor.options[selecionado];

// Volcamos la opcion al select receptor y lo eliminamos del emisor
receptor.options[posicion] = new Option(volcado.text, volcado.value);
emisor.options[selecionado] = null;
}
}
</script>
</head>

<form id="form1" name="form1" method="post" action="">
<?
include("Conexion.php");
if ($Producto==''){
$Producto= $_POST['textPro'];
$produ= "insert into producto (id_Producto, Tipo_Producto) values('id_Producto','$Producto')";
mysql_query ($produ) or die ('Error en la query: '.mysql_error());
}
else {
$Producto= $_POST['textPro'];
$eliprodu="delete from producto where Tipo_Producto='$Producto'";
mysql_query($eliprodu)or die ('Error en la query: '.mysql_error());
}

?>


<table width="100%" height="552" border="0" id="tb_externa">
<tr>
<td height="548"><div>
<div>
<table width="100%" border="0" id="tb_tecto">

<tr>
<td width="223" height="75" valign="top"><p align="left" class="style2"><img src="logo_negro.jpg" alt="espi&ntilde;eira" width="200" height="63" /><br />
</p></td>
<td width="511" rowspan="3"><div align="center">
<table width="509" height="420" border="0" cellspacing="1">
<tr>
<td width="370" height="66" valign="top"><strong>Administrador &gt; Informaci&oacute;n Producto &gt; Crear </strong>
</tr>
<tr>
<td height="200" valign="top"><div align="left">
<table width="487" height="45" border="0" cellspacing="10">
<tr>
<td width="84" height="23"><strong>Producto:</strong></td>
<td width="156"><input type="text" name="textPro"/></td>
<td width="83"><input type="submit" name="Submit3" value="Agregar" onclick="Pantalla_5_prueba.php" /></td>
<td width="96"><input type="submit" name="Submit4" value="Eliminar" onclick="Pantalla_5_prueba.php"/></td>
</tr>
</table>
</div>
<div align="center">
<table width="267" border="0" cellspacing="10">
<tr>
<td width="78">&nbsp;</td>
<td width="46">&nbsp;</td>
<td width="97">&nbsp;</td>
</tr>
<tr>

<td><?

// Incluimos el archivo de Conexion.
include ("Conexion.php");
echo "<select name='producto' style='width: 220px; height: 150px;' size='10' id='producto' multiple='multiple'>";
$sql=mysql_query("SELECT id_Producto, Tipo_Producto FROM producto");
// Creamos el Select, Utilizaremos el Bucle While para utilizar todos los productos, es mas facil que utilizar un for.
while($row=mysql_fetch_array($sql)) {

echo "<option value=‘ $row[id_Producto] ‘>$row[Tipo_Producto]</option>";
}
echo "</select>";
?> </td>
<td><input type="button" value="&gt;&gt;" onclick="volcarSelects('producto', 'producto2');" style="width:40px; height:30px;"/>
<input type="button" value="&lt;&lt;" onclick="volcarSelects('producto2', 'producto');" style="width:40px; height:30px;"/> </td>
<td><select name="producto2" style="width: 220px; height: 150px;" size="10" id="producto2" multiple="multiple">
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
<table width="200" border="0" cellspacing="10">
<tr>
<td><input type="submit" name="Submit" value="Aceptar " /></td>
<td><input type="submit" name="Submit2" value="Cancelar" /></td>
</tr>
</table>
<p align="center">&nbsp;</p>
</div>

<p align="center">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="338" valign="top"><p>&nbsp;</p>
<ul>
<li><a href="Pantalla_2_prueba.php">Inicio</a></li>
<li><a href="Pantalla_3_prueba.php">Carga de Logotipo </a></li>
<li><a href="Pantalla_4_prueba.php">Pesos Generales </a></li>
<li><a href="Pantalla_5_prueba.php">Informaci&oacute;n Producto </a>
<ul>
<li><a href="Pantalla_5_prueba.php">Crear</a></li>
<li>Modificar</li>
<li>Mostrar Preview </li>
</ul>
</li>
<li><a href="Pantalla_6_prueba.php">Informaci&oacute;n Atributos </a></li>
<li><a href="Pantalla_7_prueba.php">Informaci&oacute;n Indicadores </a></li>
<li class="style2"><a href="file:///E|/CD credito/_webadvisory/bpi_serv5.html">Informaci&oacute;n Personal </a></li>
<li class="style2"><a href="file:///E|/CD credito/_webadvisory/bpi_serv6.html">Informaci&oacute;n Financiera </a></li>
<li class="style2"><a href="file:///E|/CD credito/_webadvisory/bpi_serv6.html">Informaci&oacute;n Bur&oacute; <br />
</a></li>
<li><a href="p1.php">Salir</a></li>
</ul>
<p>&nbsp;</p></td>
</tr>
<tr>
<td height="18" valign="top">&nbsp;</td>
</tr>
</table>
</div>
</div>
<table width="100%" border="0" id="tb_logomenu">
<tr>
<td width="19%" valign="bottom"><p class="style4"><a href="file:///E|/CD credito/_webadvisory/oficinas.html"></a></p> </td>
<td width="13%" valign="bottom"><div align="right" class="style21">
<div align="center"><span class="style19"><a href="file:///E|/CD credito/_webadvisory/bpi_serv8.html"></a></span></div>
</div></td>
<td width="19%" valign="bottom"><div align="center"><a href="file:///E|/CD credito/_webadvisory/bpi_menu_serv.html" class="style2"></a></div></td>
<td width="15%" valign="bottom"><div align="left"><span class="style2"><a href="file:///E|/CD credito/_webadvisory/bpi_menu_serv2.html"></a></span></div></td>
<td width="34%" rowspan="2"><div align="right"></div></td>
</tr>
<tr>
<td height="18" valign="bottom" background="file:///E|/CD credito/_webadvisory/contacto.html">&nbsp;</td>
<td height="18" valign="bottom" background="file:///E|/CD credito/_webadvisory/contacto.html">&nbsp;</td>
<td height="18" valign="bottom" background="file:///E|/CD credito/_webadvisory/contacto.html">&nbsp;</td>
<td height="18" valign="bottom" background="file:///E|/CD credito/_webadvisory/contacto.html"><a href="file:///E|/CD credito/_webadvisory/bpi_menu_serv.html" class="style2"></a></td>
</tr>
</table> </td>
</tr>
</table>
</form>
</body>
</html>
  #4 (permalink)  
Antiguo 28/07/2009, 09:36
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Eliminar un dato en un select

Te muevo al foro de Javascript para que te orienten como trabajar con las opciones del select.

Saludos.
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.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:37.