as a follow up to my other post [URL=”http://www.webdeveloper.com/forum/showpost.php?p=1110261&postcount=2″]here[/URL], is it possible to print out the variable from within a function? In this particular case, I am trying to show the ‘soundfile’ variable I set in the playRandomSoundNoWindow function. Thanks in advance, wrathkeg
@OfekmeisterAug 24.2010 — #[CODE]<!-- code for random links to play sound files with no new window--> <script language="javascript" type="text/javascript"> function playRandomSoundNoWindow() { var myrandom=Math.round(Math.random()*2) var links=new Array() links[0]="one.mov" links[1]="two.mov" links[2]="three.mov" soundfile=links[myrandom] document.getElementById("dummy").innerHTML= '<embed id="song" src="soundfile" hidden="true" autostart="true" loop="false" />'; } </script>[/CODE]
[CODE] function WriteSong() {
var x = document.getElementById('song').src; var y = document.getElementById('text').innerHTML;
y = "This song is " + x;
} [/CODE]
with this in the body:
[CODE]<a href="#" onclick="playRandomSoundNoWindow(); WriteSong();">Click to hear music!</a><br />
@wrathkegauthorAug 24.2010 — #oops, there were loads of errors in the html code in my previous post :eek: which can't be helping... Thanks for your reply, Ofekmeister. So now I have the following, which will play the sound, but still won't write out the filename. any ideas, anyone? like I've said, I'm really new to this so any suggestions appreciated. thanks in advance,
wrathkeg <i> </i><html> <script language="javascript" type="text/javascript"> function playRandomSoundNoWindow() { var myrandom=Math.round(Math.random()*2) var links=new Array() links[0]="one.mov" links[1]="two.mov" links[2]="three.mov" soundfile=links[myrandom] document.getElementById("dummy").innerHTML= "<embed id="song" src=""+soundfile+"" hidden="true" autostart="true" loop="false" />"; function WriteSong(){ var x = document.getElementById('song').src; var y = document.getElementById('text').innerHTML; y = "This song is " + x; } } </script> <body> <a href="#" onclick="playRandomSoundNoWindow(); WriteSong();">Click to hear music!</a> <p id="text">No music is playing!</p> <span id="dummy"></span> </body> </html>
@FangAug 24.2010 — #WriteSong is nested and the references are incorrect: [CODE]function playRandomSoundNoWindow() { var myrandom=Math.round(Math.random()*2) var links=new Array() links[0]="../../Sample.mov" links[1]="../../Sample.mov" links[2]="../../Sample.mov" soundfile=links[myrandom] document.getElementById("dummy").innerHTML= "<embed id="song" src=""+soundfile+"" hidden="true" autostart="true" loop="false" />"; }
function WriteSong(){ var x = document.getElementById('song').src; var y = "This song is " + x; document.getElementById('text').innerHTML = y; }[/CODE]
@wrathkegauthorAug 24.2010 — #okay, so with your (pl.) help, I am getting really close to what I want (which is a listening test for students). this code does almost exactly what I want [CODE]<html> <script language="javascript" type="text/javascript"> function playRandomSoundNoWindow() { var myrandom=Math.round(Math.random()*2) var links=new Array() links[0]="one.mov" links[1]="two.mov" links[2]="three.mov" soundfile=links[myrandom] document.getElementById("dummy").innerHTML= "<embed id="sound" src=""+soundfile+"" hidden="true" autostart="true" loop="false" />"; } function WriteSound(){ var x = document.getElementById('sound').src; var y = "That was " + x; document.getElementById('text').innerHTML = y; } </script> <body> <OL> <LI><a href="#" onclick="playRandomSoundNoWindow(); WriteSound();">Click to hear sound</a> <LI><a href="#" onclick="playRandomSoundNoWindow(); WriteSound();">Click to hear sound</a> <LI><a href="#" onclick="playRandomSoundNoWindow(); WriteSound();">Click to hear sound</a> </OL> <p id="text">Click the sound to see what it is.</p> <span id="dummy"></span> </body> </html>[/CODE] what i am wondering now is whether there is a nifty way to change the message which pops up when clicking on the link so that some text string comes up. i.e. "if the filename is "one.mov" output "you just heard the word 'one'; if the filename is "two.mov" output "you just heard the word 'two' etc "
I guess it's possible with a series of "if" statements, but I can't figure them out. As you already know, my coding skills are pretty poor....
Thanks in advance for any suggestions, and thanks for all the help so far.
@wrathkegauthorAug 24.2010 — #one strange thing I've just noticed: the file extension gets chopped off in my usual browser (firefox on a mac), and on safari, but not Internet Explorer on PC. Anyone got any ideas why? I've googled for a while, but not come up with anything I can use.