0

Can someone tell me why this is not working:

<a href="#" onclick="play('playlist1');">Play Playlist1</a>
function play(id){
    myPlaylist.setPlaylist(id);
}

And this is working:

<a href="#" onclick="play();">Play Playlist1</a>
function play(){
    myPlaylist.setPlaylist(playlist1);
}

There is also a variable called playlist1

var playlist1 = [
    {
        title:"Title",
        artist:"artist",
        mp3: "pathtofile"
    }];

So i need the first one to set the variable to get the right playlist.

It is the same value so it really weird, but i need the first one to work

Can someone help me?

5
  • What is playlist1 in this? Can you add a JS Fiddle with the above and playlist1 etc? Commented Nov 26, 2014 at 0:40
  • 1
    In your first example, playlist1 is a string, in the second a variable. Commented Nov 26, 2014 at 0:41
  • Its a variable with the music in it. And i can;t do this in JS Fiddle because it needs alot of files Commented Nov 26, 2014 at 0:42
  • @Kevinkuijer, is it supposed to be that var playlist the input for the function onclick="play('playlist1');"? Is that what you are asking for? Commented Nov 26, 2014 at 0:48
  • Since it is impossible for the examples paged to be the actual code (missing script node), can you post examples of the actual code being used? Commented Nov 26, 2014 at 0:49

1 Answer 1

1

If your first, non-working example, you are passing 'playlist1' as a string, rather than the playlist1 variable. Simply removing the single quotes should be enough to fix it.

Example:

<a href="#" onclick="play(playlist1);">Play Playlist1</a>
function play(id){
    myPlaylist.setPlaylist(id);
}

Another solution would be to look up the variable by the string name via window[id].

Example:

<a href="#" onclick="play('playlist1');">Play Playlist1</a>
function play(id){
    myPlaylist.setPlaylist(window[id]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.