Hello guys,


I'm trying to figure out, how I could loop a function for different php generated IDs.
This is the function:
Code:
function doFirst(){ 
  maxBarSize=255; 
	
  myAudio=document.getElementById('myAudio'); 
  playButton=document.getElementById('playButton'); 
  bar=document.getElementById('defaultBar');
  progressBar=document.getElementById('progressBar');
  

  playButton.addEventListener('click', playOrPause, false); 
  defaultBar.addEventListener('click', clickedBar, false);
}
function playOrPause(){
  if(!myAudio.paused && !myAudio.ended) {
    myAudio.pause();
    playButton.innerHTML='Play'; 
    progressBar.style.WebkitAnimation= 'move 0s linear infinite'; 
    playButton.style.color='#222'; 
    window.clearInterval(updateBar);
  }else{
    myAudio.play();
    playButton.innerHTML='Pause';
    playButton.style.background= 'url("images/pause.jpg") 0 0 no-repeat'; 
    playButton.style.color='#eee'; 
    updateBar=setInterval(update, 500);
  }
}
function update(){
  if(!myAudio.ended){ /*if playing*/
    var size=parseInt(myAudio.currentTime*maxBarSize/myAudio.duration); 
    progressBar.style.width=size+'px'; /*change width in CSS*/
  }else{
    progressBar.style.width='0px';
    playButton.innerHTML='Play';
    window.clearInterval(updateBar); 
  }
}
function clickedBar(e){ 
  if(!myAudio.paused && !myAudio.ended){ /*while playing*/
    var mouseX=e.pageX-bar.offsetLeft; 
    var newtime=mouseX*myAudio.duration/maxBarSize;
    myAudio.currentTime=newtime; 
    progressBar.style.width=mouseX+'px';
  }
}
window.addEventListener('load', doFirst, false);
Now I need the function to run for myAudio1, playButton1, defaultBar1, progressBar1 and then for myAudio2, playButton2, defaultBar2, progressBar2 etc. up to maybe 300. This function itself is working properly but only for the first one. And please note that I'm coding this as a test for myself, and I've only tested it in Chrome.

I tried using things like:
Code:
var i = 0;

while(i < 100){
	document.getElementById("myAudio = " + i);
	i++;
}
If someone could help me, I would be really happy.