Jump to content

What is wrong?


jubba890

Recommended Posts

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>
Link to comment
https://forums.phpfreaks.com/topic/284888-what-is-wrong/
Share on other sites

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.  

Link to comment
https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462918
Share on other sites

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>
Link to comment
https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462938
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/284888-what-is-wrong/#findComment-1462961
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.