Combo Ajax [Resolvido]

1 resposta
realves

Ola!
To usando Struts 1 e tentando fazer um combo dependente, onde é Estado e cidade.
To usando jQuery o plugin jquery.selectboxes.js, para fazer isso, mas não consigo popular a combo.

js

$(function(){
        $('#uf').change(function(){
                if($('#uf').selectedTexts() != 'Selecione'){
                        $('#cidade').removeOption(/./);
                        $('#cidade').ajaxAddOption('selectLocal.do', {UNDF_COD: $(this).val()}, false);
                     
                }
        });
});

o select retorna um list.

Se alguém souber e puder me ajudar eu agradeço.

1 Resposta

realves

Bom já que ninguém conseguiu me ajudar, e eu demorei um tempão nisso, resolvi facilicar a vida de outra pessoa que tenha o mesmo problema, segue a solução que eu encontrei:

Tive que usar o json:

js

$('#uf').change(function() {
			$('#cidade').removeOption(/./);
			v = $(this).val();
			if ($('#uf').selectedTexts() != 'Selecione') {
				 $.getJSON("select.do",{UF:v}, showRequestTypes);
			}
		});

function showRequestTypes(data) {

	var options = [];

	for (var i = 0; i < data.length; i++) {
        options.push('<option value="',
          data[i].COD, '">',
          data[i].DES, '</option>');
    }
    $("#cidade").html(options.join(''));
}

Struts Action:

Cidade cid= (Cidade) form;
			CidadeDAO cidDao = new CidadeDAO(); 
			LinkedList<Cidade> list = CidadeDao.comboCidade(cid); 
			
			JSONArray json = JSONArray.fromObject(list); 
				 
			response.getWriter().print(json);
			response.getWriter().close();

Até a próxima :wink:

Criado 13 de janeiro de 2011
Ultima resposta 23 de jan. de 2011
Respostas 1
Participantes 1