In my program I create buttons with javascript and they should start an function but they don't. If I press the button on my program the browser says "can't find variable" how can I fix it that the button starts the function.
JS-Code
$(document).ready(function(){
function myfunction() {
alert("pls");
}
var Id = sessionStorage.getItem('Id');
var status = 0;
var nummer = 0;
$.ajax({
type: "POST",
url: "http://localhost/jQuery&PHPnew/Markt.N.php",
data:{status:status},
success: function(data){
    var anzahl = 1;
    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("type", "button");
          bInhalt.setAttribute("onclick", "myfunction()");
          f.appendChild(bInhalt);
          Ausgabebereich.appendChild(f);
        }
       })
      }
     }
    })
  })
