Jump to content

Recommended Posts

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. :)

Link to comment
https://forums.phpfreaks.com/topic/236910-echo-with-javascript/
Share on other sites

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>'; ?>

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 :)

 

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.

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. :(

 

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".

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.