mrt003003 Posted May 19, 2011 Share Posted May 19, 2011 Hi there im having real trouble trying to combine a php echo hyperlink with a javascript link. Is this possible?? Heres my echoed link: <?php echo '<a href="http://localhost/swb/fleet.php?recordID='.$row_Fleet['FleetName'].'"> <IMG SRC="',$pic1,'" WIDTH="12" HEIGHT="10" BORDER="0" ALT="" CLASS="fmoncalamari"></a>'; ?> Heres the Javascipt: <a href="javascript:play_multi_sound('multiaudio1');">Flute</a> Ive been trying combine the two so it will hopefullly then hyperlink an image and play an audio file. Its not working <?php echo '<a href="http://localhost/swb/fleet.php?recordID='.$row_Fleet['FleetName'].' javascript:play_multi_sound('multiaudio1');"> <IMG SRC="',$pic1,'" WIDTH="12" HEIGHT="10" BORDER="0" ALT="" CLASS="fmoncalamari"></a>'; ?> Im really new to Javascript and so any ideas on how i can combine them would be ace Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/236910-echo-with-javascript/ Share on other sites More sharing options...
jcbones Posted May 19, 2011 Share Posted May 19, 2011 Have you tried? <?php echo '<a href="http://localhost/swb/fleet.php?recordID='.$row_Fleet['FleetName'].'" onclick="play_multi_sound(\'multiaudio1\');"> <IMG SRC="',$pic1,'" WIDTH="12" HEIGHT="10" BORDER="0" ALT="" CLASS="fmoncalamari"></a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236910-echo-with-javascript/#findComment-1217815 Share on other sites More sharing options...
mrt003003 Posted May 19, 2011 Author Share Posted May 19, 2011 Thanks for the reply, when i do it this way the hyperlink and parsed id works fine but the audio doesnt work. Heres the code im using: <script type="text/javascript"> var channel_max = 10; // number of channels audiochannels = new Array(); for (a=0;a<channel_max;a++) { // prepare the channels audiochannels[a] = new Array(); audiochannels[a]['channel'] = new Audio(); // create a new audio object audiochannels[a]['finished'] = -1; // expected end time for this channel } function play_multi_sound(s) { for (a=0;a<audiochannels.length;a++) { thistime = new Date(); if (audiochannels[a]['finished'] < thistime.getTime()) { // is this channel finished? audiochannels[a]['finished'] = thistime.getTime() + document.getElementById(s).duration*1000; audiochannels[a]['channel'].src = document.getElementById(s).src; audiochannels[a]['channel'].load(); audiochannels[a]['channel'].play(); break; } } } </script> <audio id="multiaudio1" src="Music/reb.wav" preload="auto"></audio> <audio id="multiaudio2" src="Music/emp.wav" preload="auto"></audio> <?php echo '<a href="http://localhost/swb/fleet.php?recordID='.$row_Fleet['FleetName'].'" onclick="play_multi_sound(\'multiaudio1\');"> <IMG SRC="',$pic1,'" WIDTH="12" HEIGHT="10" BORDER="0" ALT="" CLASS="fmoncalamari"></a>'; ?> Ive tested the javascript independantly and it works fine... Its just not working with the php. Am i missing something?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/236910-echo-with-javascript/#findComment-1217822 Share on other sites More sharing options...
jcbones Posted May 19, 2011 Share Posted May 19, 2011 Nope, I suppose the audio works on hover, or when you mouseover the anchor. If so, then it will not work, as I have set it to work only when you click it. You could fix it by changing the 'onclick' to a 'onmouseover'. However, most see this the same way as inline CSS styling, which means 'It is ok to do it, but it is not considered professional'. The following note is for reference only The suggested fix is to set it through the DOM on an event listener. Quote Link to comment https://forums.phpfreaks.com/topic/236910-echo-with-javascript/#findComment-1217826 Share on other sites More sharing options...
mrt003003 Posted May 19, 2011 Author Share Posted May 19, 2011 No the audio doesnt work on mouseover or hover, it was meant to only sound when clicked and it works when it is in just html: <a href="javascript:play_multi_sound('multiaudio1');">Sound1</a> Just trying to modiy the existing php hyperlink with it, is when it doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/236910-echo-with-javascript/#findComment-1217829 Share on other sites More sharing options...
DavidAM Posted May 19, 2011 Share Posted May 19, 2011 Why did you start a new topic for the same problem? That's against the rules. To address your problem, I would try moving the onclick to the IMG tag. It may be that the IMG tag is "eatting" the click event so the A tag does not actually see it. Of course, this is just a "shot in the dark". Quote Link to comment https://forums.phpfreaks.com/topic/236910-echo-with-javascript/#findComment-1217853 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.