Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/09/2008, 23:18
ikyrhc
 
Fecha de Ingreso: septiembre-2008
Ubicación: iztacalco
Mensajes: 1
Antigüedad: 15 años, 8 meses
Puntos: 0
listbox dinamico

Hola:
pues... pues... andando en este camino de la red, estube buscando la manera de hacer un listbox dinamico, que me permita agregar y seleccionar un valor adicional, espero darme a entender, supongamos, que tengo 3 valores en la lista, pero, si en esa lista no esta el valor que quiero, bueno pues, selecciono el valor de agregar uno nuevo y voila!!! se agrega, y seleccionado.

Espero sea de utilidad he aki el codigo:

Código HTML:
<html>
<head>
	<title>Lista Editable</title>
	<script language="javascript">
	//autor iky.rhc------------------------
	function ingresaValor()
	{
		var i=document.miFormulario.miLista.selectedIndex;
		var i2=document.miFormulario.miLista.length;		
		var value = document.miFormulario.miLista.options[i].text;
		if (value == "Nuevo_valor")
		{
			MiVariable=prompt("Ingresa valor nuevo");
			var ni2 = i2 + 1;
			document.miFormulario.miLista.length = ni2;
			document.miFormulario.miLista.options[i2].text = MiVariable;
			document.miFormulario.miLista.options[i2].value = MiVariable;
			document.miFormulario.miLista.options[i2].selected = true;
			document.miFormulario.miLista.focus();
			alert("valor agregado: " + MiVariable + " en la posicion: " + ni2);
		}
	}
	
	</script>
</head>

<body>
<div name="test">
<form name="miFormulario">
<table> 
	<tr>
		<td colspan="2">
		<h4>Selecciona un valor</h4>
		</td>
	</tr>
	<tr>
		<td>Valores en lista:</td>
		<td>
		<select name="miLista" style="width:150px" onChange="ingresaValor();">
			<option>Mi_trabajo</option>
			<option selected>Mi_novia</option>
			<option>mi_casa</option>
			<option>Nuevo_valor</option>		
		</select>
		</td>
	</tr>
</table>
</form>
</div>
</body>
</html>