as a follow up to my other post here, 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
<!-- 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:
function WriteSong()
{
var x = document.getElementById('song').src;
var y = document.getElementById('text').innerHTML;
y = "This song is " + x;
}
with this in the body:
Code:
<a href="#" onclick="playRandomSoundNoWindow(); WriteSong();">Click to hear music!</a><br />
<p id="text">No music is playing!</p>
Last edited by Ofekmeister; 08-23-2010 at 09:12 PM.
oops, there were loads of errors in the html code in my previous post 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
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=\"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>
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;
}
At least 98% of internet users' DNA is identical to that of chimpanzees
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>
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.
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.
thanks in advance,
wrathkeg
Bookmarks