I have several buttons that use the same implementation but need to pass a different parameter to the function. This if for an mp3 player for context. My idea should be easy to follow, but I cannot get the syntax to work. Hope someone can help.
The button in HTML:
<input id="songToPlay" type="button" value="Click To Play!"/>
Then the javascript onclick call:
document.getElementById('songToPlay').onclick = playSongByThisBand;
The method playSongByThatBand():
function playSongByThisBand() {
playSongByAnyBand(theIntegerThatRepresentsThisBand);
}
The method playSongByAnyBand(parameter):
function playSongByAnyBand(anIntegerThatRepresentsABand) {
currentSongIndex=anIntegerThatRepresentsABand;
//other implementation ect...
}
An alternative approach I tried is:
function playSongByAnyBand(anIntegerThatRepresentsABand) {
currentSongIndex=anIntegerThatRepresentsABand;
someObject = function() {other implementation ect...}
}
var functionIWantToExecutre = new playSongByAnyBand(anIntegerThatRepresentsABand)
functionIWantToExecute.someObject();
I cannot get playSongByAnyBand to execute. I could implement each button separately but that is even more redundant that my approach already. Can anyone help me with the syntax to implement multiple buttons this way?
anIntegerThatRepresentsABandcome from?