title: javascript: set onclick function with a parameter for a button
body: <p>I have created a button using javascript and now I want to give it a onclick. however I want the function to have a parameter i. the problem is that when I inspect the console the onclick function is just onclick=playAudio(i). I want it to be different for each value of i in the for loop, but because it is in brackets it just stays as i instead of the current number in the for loop. I hope I have explained this properly. some of the code is below to help you understand.</p>
  
  <pre><code>var i;
  var audioMp3 = ["audio/Un", "audio/Deux", "audio/Trois", "audio/Quatre", "audio/Cinq", "audio/Six", "audio/Sept", "audio/Huit", "audio/Neuf", "audio/Dix"];
  
  for(i = 0; i &lt; audioMp3.length; i++{
      var audioBtn = document.createElement("BUTTON");
      audioBtn.setAttribute("onclick", "playAudio(i);";
  }
  </code></pre>