jubba890 Posted December 21, 2013 Share Posted December 21, 2013 Okay so what is supposed to happen is that whatever the user selects in the listbox the song is supposed to then play, but I cannot even get that far because I get an error. <!DOCTYPE html> <html> <head><title>Test Music App/title></head> <body> <select name="Songs" multiple="multiple" onchange="playsong($song)"> <option>Nicki Minaj - Five-O.mp3</option> <option>text2</option> <option>text3</option> <option>text4</option> <option>text5</option> </select> <?php> function playsong($song); { <audio controls> <source src="http://www.inzernettechnologies.com/StreamIT/media/music/$song.mp3" type="audio/mpeg"> <embed height="150" width="400" src="http://www.inzernettechnologies.com/StreamIT/media/music/$song.mp3"> </audio> } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284888-what-is-wrong/ Share on other sites More sharing options...
KevinM1 Posted December 21, 2013 Share Posted December 21, 2013 Defining a function is different than invoking/running a function. Something like: function someFunction($x) { // do something with $x } Is a function definition. But that's all it is. It doesn't run right then and there. Function invocation looks like: someFunction($x); Look at your code - you're blending them together (note where you have the semicolon, and how you have a code block following it... that's incorrect syntax). You need to define a function before you can run it. Quote Link to comment https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462918 Share on other sites More sharing options...
jcbones Posted December 21, 2013 Share Posted December 21, 2013 To add to Kevin's post, PHP is not javascript, and cannot run via an "onchange" event. You would need javascript for that, as PHP never sees what a client does, only what a client sends to the server. Quote Link to comment https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462919 Share on other sites More sharing options...
JIXO Posted December 21, 2013 Share Posted December 21, 2013 So much wrong. Defining a javascript function as a PHP function, can't help with this . Quote Link to comment https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462920 Share on other sites More sharing options...
Solution ignace Posted December 22, 2013 Solution Share Posted December 22, 2013 You may want to learn JavaScript first before continuing on your journey. You will safe yourself hours of frustration. You don't simply burst into China and then hope to learn their language. You learn chinese first and then you go to China. <!DOCTYPE html> <html> <head> <title>Test Music App/title> </head> <body> <select name="Songs" height="150" onchange="playsong(this.options[this.selectedIndex].value)"> <option>Nicki Minaj - Five-O</option> <option>text2</option> <option>text3</option> <option>text4</option> <option>text5</option> </select> <script> function playsong($song) { alert('Playing ' . $song); var container = document.createElement('div'); container.innerHTML = '<audio controls>\ <source src="http://www.inzernettechnologies.com/StreamIT/media/music/'+$song+'.mp3" type="audio/mpeg">\ <embed height="150" width="400" src="http://www.inzernettechnologies.com/StreamIT/media/music/'+$song+'.mp3">\ </audio>'; document.body.appendChild(container); } </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462938 Share on other sites More sharing options...
KevinM1 Posted December 22, 2013 Share Posted December 22, 2013 To add to Kevin's post, PHP is not javascript, and cannot run via an "onchange" event. You would need javascript for that, as PHP never sees what a client does, only what a client sends to the server. I didn't even notice they were trying to invoke it via on change. Yeah, that won't work. Basically, the answer is learn to code. Quote Link to comment https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.