Fill in a jquery combobox

1

See a combo is not popular, that's what I do. The combo is populated, there I need to get the id and show in the combo the text referring to that ID. The ID I have in my table, just need to show the text in the combo. My jquery looks like this:

function CarregaDados(ajaxParameter) {
    $.ajax({

        url: '/CadastroAcesso/CarregaDadosPagina',
        datatype: 'json',
        contentType: 'application/json;charset=utf-8',
        type: 'POST',
        data: JSON.stringify({ _nivel: ajaxParameter }),
        success: function (data) {

            $.each(data, function (index, itemData) {
                $('#txtNome').val(itemData.NM_Usuario);
                $('#txtUsuarioRede').val(itemData.Usuario1);
                $('#txtEmail').val(itemData.Email);
                //$('#cbxNivelAcesso').val();
            });
        },
        error: function (error) {

        }
    })
}

cbxNivelAcesso is my combo. It's commented because I tested it in many ways and nothing.

    
asked by anonymous 05.11.2014 / 19:05

1 answer

1

I do not quite understand what you want. But I'll show you two options, either by taking the value of the selected text from the combo, or by passing the value of the option to retrieve the text.

$("#cbxNivelAcesso").children("option").filter(":selected").text();

or by passing the value

$("#cbxNivelAcesso option[value='2']").text()
    
05.11.2014 / 19:45