That's my code:
afficherListe();
function afficherListe()
{
$.post('afficher_liste.php', function(data)
{
var obj = jQuery.parseJSON(data);
if(data!="")
{
$.each(obj, function(index, value){
$('<li><button onclick="supprimer_article()">X</button>'+value.nomArticle+' '+value.prixArticle+'</li>').insertAfter($('#liste_boissons'));
});
}
else
{
alert('no data');
}
});
}
function supprimer_article(article_selectionne)
{
alert(article_selectionne);
}
Problem : I want to put my variable in supprimer_article() function, to have it in parameter and to continue my work in the function.
Example : If I click on "X" Vodka button (view picture), I would find inalert(article_selectionne); "Vodka"
In a primary step, I've put the variable like that :
$('<li><buttononclick="supprimer_article('+value.prixArticle+')">X</button>'+value.nomArticle+' '+value.prixArticle+'</li>').insertAfter($('#liste_boissons'));
But, the result in alert(article_selectionne); was : UNDEFINED
If you think you have the solution, it would be very nice and helpful to share it for me !
To have an idea of what do this function now (the final goal is that this function will remove the selected article from the DB after the onclick event....) :
