Hi I am new to jquery actually I had an dropdown in my html where I will get the options from database using ajax here I am retrieving the id and option from database but showing only the options in the dropdown
The code for dropdown which I done so far in html is
<div id="container" class=""></div>
<button id="seedoc" style="float: right; margin-right: 10px;" onclick="addOne();"></button>
function addOne() {
getEmails();
$('#container').append(
<div class='form-group' style='display:flex'>
<select class='drop form-control' name='option' id='option'>
<option value='' disabled selected>Select your option</option>
</select>
<button class="btn btn-primary shrBtn" style="float:left;" onclick="send()">Send</button>
</div>
the json response I get from db.php is
users:
[ "<p style='margin:0px;display:none;'data-id='755'>amilham</p>",
"<p style='margin:0px;display:none;'data-id='706'>a_sarabi</p>"]
and in dropdown I am getting amilham,a_sarabi so here in the dropdown if I select amilham I need to get the data-id i.e 755 into an array and also in the another dropdown if I select a_sarabi I need to get 706 into array using jquery
can anyone help me please
so far I tried like this but not getting
function send()
{
var uids = [];
\$('.drop').change(function(){
\$(this).find('option:selected').each(function(){
uids.push(\$(this).attr('data-id') );
});
});
I need all the ids of selected options in all the dropdowns I add using jquery Populating options from db into dropdown
function getEmails(){
\$.ajax({
url :'propage.php',
type : 'POST',
dataType : 'json',
data : '&userId='+\$('#hdn_userid').val()+'&action=getEmails',
success : function(res){
res.users.forEach(function(option) {
\$('.drop').append('<option>' + option + '</option>');
});
},
});
}