Combobox carregando Combobox

1 resposta
R

Pessoal,

Tenho uma comobobox que carrega outra pela função onChange

Eu consigo submeter o que for selecionado, porem eu preciso dar um select nela para gravar o que eu escolher nas combos na hora que eu der o submit

mas como meu não possui não sei como fazer isso!!!

uso uma função carrLista() que recebe dois parametros para carregar as combos

Alguem poderia me ajudar???

segue ai meu codigo pessoal

<script type="text/javascript">

function carrLista(strComboAtual, strComboNovo)
		{			
			xml = '<%=com.sabesp.tiposinformacao.RunTiposInformacao.getXML(request)%>';			
			var el = document.getElementById(strComboAtual);
			var el2 = document.getElementById(strComboNovo);
			var path = "";

						
			removeLista(strComboAtual);
			
			if(strComboNovo == "comboAssuntoNivel1")
			{
				 path = "/taxonomia/categoria[@nivel='1']";

			}else if(strComboNovo == "comboAssuntoNivel2")
			{
			
				if(el.options[el.selectedIndex].text == "")
				{
					return;
				}else{				
					 path = "/taxonomia/categoria[@title='"+ el.options[el.selectedIndex].text +"']";
				}

			}else if(strComboNovo == "comboAssuntoNivel3"){

				
				if(el.options[el.selectedIndex].text == "")
				{
					return;
				}else{		
					path = "/taxonomia/categoria/categoria[@title='"+ el.options[el.selectedIndex].text +"']";
				}
			}

			try //Internet Explorer
			{
				  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				  xmlDoc.async="false";
	 			  xmlDoc.loadXML(xml); 			  
	 			  
	 			  var nodes= xmlDoc.selectNodes(path);
			  	  var childNodes;

	 			if(strComboNovo == "comboAssuntoNivel1")
				{
					var childNodes = nodes;	
				}else{
					var childNodes = nodes[0].childNodes;		
				}
			
				

				var y= document.createElement('option'); 
			    y.text= ""; 
		    	el2.add(y);
		    	
				for (i=0;i< childNodes.length;i++)
				{
					y = document.createElement('option'); //cria um novo elemento option
				    y.text= childNodes[i].getAttribute('title'); //seta o texto do elemento option
			    	el2.add(y); // adiciona um novo option antes do indice selecionado para navegadores complacentes
				}	
				sortselect(el2);
				  
			}catch(e)
			{
			  try { //Firefox, Mozilla, Opera, etc.
				  xmlDoc=document.implementation.createDocument("","",null);
				  parser=new DOMParser();				  
				  xmlDoc=parser.parseFromString(xml,"text/xml");				  
				  var nodes  = document.evaluate(path, xmlDoc, null , XPathResult.ANY_TYPE , null);	  
				  var childNodes;
				  var node;
				  if (strComboNovo == "comboAssuntoNivel1") {					  
					var childNodes = nodes;	
					node = childNodes.iterateNext();
					el2.options[el2.options.length] = new Option("", "");					
					while (node) {					  
					  el2.options[el2.options.length] = new Option(node.getAttribute('title'), node.getAttribute('title'));
					  node = childNodes.iterateNext();
			      	}							
				  }else{
					node = nodes.iterateNext();		
					childNodes = node.childNodes;									
					el2.options[el2.options.length] = new Option("", "");					
					for (i=0;i< childNodes.length;i++) {
						 node = childNodes[i];
						 el2.options[el2.options.length] = new Option(node.getAttribute('title'), node.getAttribute('title'));
					}												
				  } 
				sortselect(el2);	
			  }catch(e)
			  {
			  	alert(e.message);
			  }
  			}
		  
		}

</script>

<tr>
					<td>
					<span class="tituloSelectBusca">Selecione um assunto:</span>
				</td>
					
					<td>
						<select id="comboAssuntoNivel1" class="selectBusca" 
						onChange="carrLista('comboAssuntoNivel1','comboAssuntoNivel2')">
						</select>
					</td>
				
				<tr>
					<td>
						<span class="tituloSelectBusca"></span>
					</td>
					
					<td>
						<select id="comboAssuntoNivel2" class="selectBusca"
						onChange="carrLista('comboAssuntoNivel2','comboAssuntoNivel3')">
						</select>
					</td>
				</tr>
				
				<tr>
					<td>
						<span class="tituloSelectBusca"></span>
					</td>
					<td>
						<select class="selectBusca" id="comboAssuntoNivel3">
						</select>
					</td>
				</tr>

Desde ja Grato

1 Resposta

rdgms

Aew!!!
Você não esta usando framework nenhuma neh?
então caso você realmente não esteja usando eu aconselho você a utilizar o Jquery…
ai voce substitui linhas de codigo por:

$('#suaDivDaCombo').load('suaServlet','parametros:valor',function(data){
    //sua logica
});
Criado 13 de março de 2009
Ultima resposta 13 de mar. de 2009
Respostas 1
Participantes 2