I want to use a button with OnClick that I created with JS. I can create the button and I also get the attribute on to the Button but the Button doesn't start my function he only reset the Website.
$.ajax({
type: "POST",
url: "http://localhost/jQuery&PHPnew/Markt.N.php",
data:{status:status},
success: function(data){
var anzahl = data;
status = 1;
while (anzahl>nummer) {
nummer++;
$.ajax({
type: "POST",
url: "http://localhost/jQuery&PHPnew/Markt.N.php",
data:{nummer:nummer, status:status},
success: function(data){
var Daten = JSON.parse(data);
var Ausgabebereich = document.getElementById('main');
var f = document.createElement("form");
var bInhalt = document.createElement('button');
var Inhalt = document.createTextNode("Senden");
bInhalt.appendChild(Inhalt);
bInhalt.setAttribute("onclick", "myfunction()");
f.appendChild(bInhalt);
Ausgabebereich.appendChild(f);
}
})
}
}
})
function myfunction() {
alert("pls");
}
This is the code created in the browser