5

I am trying to insert a variable passed to my function into the output of my .innerHTML = code but do not know how to properly insert it into the HTML output.

function playsong(song)
{
    parent.document.getElementById('player').innerHTML = '<object width="199" height="26"><param name="movie" value="audio_player_black.swf"><embed src="audio_player_black.swf?audio_file=upload/'[song]'&color=00000" width="199" height="26"></embed></object>';
}

I just get [song] in my HTML output rather than the value of [song]

Not sure how I need to do this properly

3 Answers 3

10

easy:

parent.document.getElementById('player').innerHTML = '<object width="199" height="26"><param name="movie" value="audio_player_black.swf"><embed src="audio_player_black.swf?audio_file=upload/'+song+'&color=00`000" width="199" height="26"></embed></object>';

just like concatenating any 2 + strings

Sign up to request clarification or add additional context in comments.

Comments

6

Instead of:

[song]

use:

 +song+

1 Comment

You'll need to terminate the string beforehand and then reopen it afterward, too.
0

In place of [song] use +song+. It's a concatenate function that will add the value.

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.