user2383686
user2383686

Reputation: 1

HTML audio onplay function calling

I have function 'a', and i'd like to call function 'b' when the audio starts. i can call it when 'b' has no argument or the argument is a string, but it's not working when the argument is a variable.

function a(p){
        p.innerHTML= "<audio preload='auto' id='beep1' autoplay='true' onplay='b(p)'><source src='sounds/beep1.mp3' type='audio/mp3' /><source src='sounds/beep1.mp3' type='audio/mp3' /></audio>";
}

Upvotes: 0

Views: 307

Answers (1)

Ian
Ian

Reputation: 6104

That's because p is not defined. You are inserting a string into HTML code. When you insert it, that variable no longer refers to the function-specific variable because it's part of the HTML, not the function. You have to define the variable separately somehow. If you post more code or a Fiddle, I can help more.

Upvotes: 1

Related Questions