Get select selected (only getting first value)


An alert is displayed (with the sweetalert plugin) and in this alert has a select with names. After selecting the name, the person has to click the Add button, when the person clicks the function of the code below is executed and in it I put a code to capture the selected option , only the result is always that of the first option .


                var conteudoListaPresente = $("#contentLP").html();
                var id_produto = $(this).attr('ref');
                var baseURL = $("#baseURL").val();

                  title: "Adicionar a Lista de Presentes",
                  text: conteudoListaPresente,
                  html: true,
                  showCancelButton: true,
                  closeOnConfirm: false,
                  closeOnCancel: true,
                  cancelButtonText: 'Cancelar',
                  confirmButtonText: 'Adicionar'

                    var selecionado = $("#ListaPresenteSelect option:selected");


                    if($.trim(selecionado) !=  false){


                            url: baseURL+'ajax/adicionaritemlistadepresentesx',
                            type: 'POST',
                            data:{id:selecionado, produto:id_produto},


                                    swal("Adicionado!", "Produto adicionado a sua lista de casamento (:", "success");
                                    swal("Opss", "Ocorreu um erro ao adicionar o produto: "+callback, "error");


asked by anonymous 01.11.2015 / 02:29

2 answers


There are a few ways to get value, as you do not have your HTML I'll name a few:

If your form does not have the value attribute, something like:

<select id="ListaPresenteSelect">

You can take it straight, like this:



If you have a value attribute and you want to access it, just use the example described above.


If you have a value and you want to get the selected text you can do this:

$('#ListaPresenteSelect option:selected').text();


In your example above, it seems to be missing just getting the text with the method .text() .

01.11.2015 / 03:11

This will select what is clicked

$(document).ready(function () {

    // get estado

    var estado = $('select');


    estado.change(function () {
    //final get estado
18.03.2017 / 17:24