7
An Alert is displayed (with the sweetalert plugin) and in that Alert has a select
with names. After selecting the name, the person has to click the button Add, when the person clicks the function
of the code below is executed and in it I put a code to capture the option
selected, only that the result is always that of the first option
.
$("a#AddListaPresentes").click(function(){
var conteudoListaPresente = $("#contentLP").html();
var id_produto = $(this).attr('ref');
var baseURL = $("#baseURL").val();
swal({
title: "Adicionar a Lista de Presentes",
text: conteudoListaPresente,
html: true,
showCancelButton: true,
closeOnConfirm: false,
closeOnCancel: true,
cancelButtonText: 'Cancelar',
confirmButtonText: 'Adicionar'
},function(){
var selecionado = $("#ListaPresenteSelect option:selected");
alert(selecionado);
if($.trim(selecionado) != false){
$.ajax({
url: baseURL+'ajax/adicionaritemlistadepresentesx',
type: 'POST',
data:{id:selecionado, produto:id_produto},
success:function(callback){
if(callback){
swal("Adicionado!", "Produto adicionado a sua lista de casamento (:", "success");
}else{
swal("Opss", "Ocorreu um erro ao adicionar o produto: "+callback, "error");
}
}
});
}
});
})
the worst is that it didn’t work. When I click on "Add" it gives Alert only that the result only comes out 1 (which is the value of the first item). I do not know if there is something, but this "Add" is a button of the plugin that only makes the
function
of the code I posted.– Alisson Acioli
better look at that jsfiddle hehe'
– Brunno
I don’t understand why o.o.. Because in mine it looks like the code of the
jsdiddle
... The only difference is that the <select> is rendered in a<div>
with thedisplay:hidden
and when the person clicks on a link jQuery takes theHTML
of thatdiv
and plays in the plugin to display select with options– Alisson Acioli
Just to clarify, your select stays within the modal generated by sweetalert ? :D
– Brunno
Yes, I managed to.. It was because how I picked up the rendered content of
<div>
who was withdisplay:none
and then just create another one and put inside the modal, so was 2 select with the same name and gave dick... I managed to fix.. Thank you!– Alisson Acioli
@Alissonacioli forgot to upvote and close that ;) ... (then delete this comment...)
– gustavox