Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Problema con dos selects independientes

Estas en el tema de Problema con dos selects independientes en el foro de Frameworks JS en Foros del Web. en mi codigo tengo dos inputs y dos selects, cada input funciona como un buscador para cada select, es decir, el usuario debe introducir en ...
  #1 (permalink)  
Antiguo 10/07/2008, 11:11
 
Fecha de Ingreso: julio-2008
Mensajes: 5
Antigüedad: 15 años, 9 meses
Puntos: 0
Problema con dos selects independientes

en mi codigo tengo dos inputs y dos selects, cada input funciona como un buscador para cada select, es decir, el usuario debe introducir en un input lo que quiere buscar y los resultados saldran listados en el select para que solo elija uno.
Obvio esto se hace con ajax.
cuando busco en un input solamente me funciona a la perfeccion, pero si busco en uno y despues busco en el otro, ambos selects son modificados con el resultado de la segunda busqueda. 0.0?
intente destruir el objeto XMLHttpRequest pero no funciono. les dejo el codifo para que me entiendan mejor



Código:
ajaxSPA = null;
  function getServicioSPA( id, sucId, true ){
  	alert("spa javasc");
	valor = document.getElementById( id ).value;
	ajaxSPA = nuevoAjax();
	ajaxSPA.open( "post", "/EdithJacobo/ventas/buscserviciospa" );
	ajaxSPA.onreadystatechange = getServSPA;
	ajaxSPA.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
	ajaxSPA.send( "busServ="+valor+"&sucId="+sucId );
  }

  function getServSPA(){
  	switch( ajax.readyState ){
  		case 1:
  		alert("spa metodo");
	  		document.getElementById('cargandoSPA').style.display= 'inline';
  		break;
  		case 4:
	  		document.getElementById('cargandoSPA').style.display= 'none';

  			var selecc = document.getElementById('producto_idSPA');
  			selecc.innerHTML = "";
				var productos = ajaxSPA.responseXML.childNodes[0];
				for( var i = 0; i < productos.childNodes.length;  i++ ){
					var opcion = document.createElement('option');
					opcion.value = productos.childNodes[i].getAttribute('id')
					document.getElementById('precSPA').value = productos.childNodes[i].getAttribute('precio')
					opcion.innerHTML = productos.childNodes[i].textContent;
					selecc.appendChild( opcion );
				}
				ajaxSPA.abort();
				ajaxSPA = null;
  	}
  }

  ajaxProd = null;
  function getProducto( id, sucId ){
  alert("prod javasc");
	valor = document.getElementById( id ).value;
	if( valor != "" ){
		ajaxProd = nuevoAjax();
		ajaxProd.open( "post", "/EdithJacobo/ventas/buscprod" );
		ajaxProd.onreadystatechange = getProd;
		ajaxProd.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
		ajaxProd.send( "busProd="+valor+"&sucId="+sucId );
	}
	else{
		document.getElementById('existProd').innerHTML ="";
		document.getElementById('precProd').innerHTML ="";
		document.getElementById('producto_idProd').innerHTML ="";
	}
  }

  function getProd(){
  	switch( ajax.readyState ){
  		case 1:
  		alert("metodo prod");
	  		document.getElementById('cargandoProd').style.display= 'inline';
  		break;
  		case 4:
	  		document.getElementById('cargandoProd').style.display= 'none';

  			var selecc = document.getElementById('producto_idProd');
  			selecc.innerHTML = "";
				var productos = ajaxProd.responseXML.childNodes[0];
				for( var i = 0; i < productos.childNodes.length;  i++ ){
					var opcion = document.createElement('option');
					opcion.value = productos.childNodes[i].getAttribute('id')
					opcion.innerHTML = productos.childNodes[i].textContent;
					document.getElementById( 'existProd' ).value = productos.childNodes[i].getAttribute('cantidad');
					document.getElementById( 'precProd' ).value = productos.childNodes[i].getAttribute('precio');
					selecc.appendChild( opcion );
				}
				ajaxProd.abort();
				ajaxProd = null;
  	}
  }
ya con esto puedo agregar, puse alerts para saber como es que funcionaba esto, por ahi se pueden ver en el codigo. cuando se ejecuta la funcion getProducto, despues de haber ejecutado la funcion getServicioSPA, me lanza los alerts:
"prod javasc", "metodo prod" y "spa javasc", es decir la funcion getServiSPA se llama sin que yo la haya llamado. o si primero llamo a getServicioSPa la que se llama sin que yo lo haya hecho es getProd()

@.@

ayudaaaa!!

aqui esta mi html:
Código HTML:
<fieldset style="border-color:#333366; border-style:solid; width: 350px; padding:5px; clear:none; margin=5px; display:inline">
		<legend>Servicios de SPA</legend>
		<form action="/EdithJacobo/ventas/detalleventa/1" method="post">
				<img src="/EdithJacobo/img/buscar.png" width="15" heigth="15" />Buscar servicio:
				<input name="data[Servicio][buscarP]"  id="buscarSS" onkeyup="getServicioSPA(this.id,2)" value="" type="text" /><br>
			Servicio:
				<select name="data[Servicio][servicio_id]"  id="producto_idSPA">

<option value="" >&nbsp;</option>
</select><img src="/EdithJacobo/img/cargando.gif" width="15" heigth="15" style="display:none" id="cargandoSPA" /><br><br>
			Precio:<input name="data[Servicio][precio]"  size="4" id="prec" disabled="disabled" value="" type="text" /><br><br>
			Cantidad:
				<input name="data[Servicio][cantidad]"  id="cantidad" size="4" value="" type="text" />			Descuento(%):
				<input name="data[Servicio][descuento]"  id="descuento" size="5" value="" type="text" /><br><br>
			<input type="submit" value="Agregar" /> </form>
	</fieldset>

	<fieldset style="border-color:#333366; border-style:solid; width: 350px; padding:5px; clear:none; margin=5px; display:inline">

		<legend>Productos</legend>
		<form action="/EdithJacobo/ventas/detalleventa/1" method="post">
				<img src="/EdithJacobo/img/buscar.png" width="15" heigth="15" />Buscar producto:
				<input name="data[Producto][buscarP]"  id="buscarP" onkeyup="getProducto(this.id,2)" value="" type="text" /><br>
			Producto:
				<select name="data[Producto][producto_id]"  id="producto_idProd">
<option value="" >&nbsp;</option>
</select><img src="/EdithJacobo/img/cargando.gif" width="15" heigth="15" style="display:none" id="cargandoProd" /><br><br>
			Precio: <input name="data[Producto][precio]"  size="4" id="precProd" disabled="disabled" value="" type="text" />			Existencia: <input name="data[existProd][]"  size="4" id="existProd" disabled="disabled" value="" type="text" /><br><br>

			Cantidad:
				<input name="data[Producto][cantidad]"  id="cantidadProd" size="4" onchange="validarCant(this.value)" value="" type="text" />			Descuento(%):
				<input name="data[Producto][descuento]"  id="descuentoProd" size="5" value="" type="text" /><br><br>
			<input type="submit" value="Agregar" /> </form>
	</fieldset> 
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 12:54.