I have a small confirm that displays data on the page for the user to re-read and to see if he made any mistakes and I have included a list of categories but I can't manage to display them in the confirm My code is below:
$("#add_campaign").on('submit', function(event){
if(!confirm("Confirm:\n" +
"\nCategorii selectate: " + categoriesInConfirm() +
"\nContinue?")) {
event.preventDefault();
}
});
});
function categoriesInConfirm()
{
$('#newCategories li span').each(function (index,value){
$(value).text())
})
}
I used the following line in my console to check if I can get the list and it works:
$('#newCategories li span').each(function (index,value){console.log($(value).text())})
I don't know how to implement it in my coding environment
Your function needs to return value like this.
function categoriesInConfirm()
{
var cats = '';
$('#newCategories li span').each(function (index,value){
console.log($(this) + ' ,' + $(this).text());
cats += $(this).text() +', ';
});
cats = cats.substring(0, cats.length - 2); // remove last ,
return cats;
}