justincredible
08-31-2006, 02:27 PM
I have a script that I want to display a lyric from a song and then change the lyric every so many seconds. Problem is I can't seem to get it to work.
Here is what I have:
Here is where I call the function...
<p>
<script>
<!--
getLyric();
//-->
</script>
</p>
Here is the function...
function randomNumber()
{
var ranNum= Math.floor(Math.random()*4);
return ranNum;
}
function getLyric()
{
var number=randomNumber();
var lyric=new Array(4);
lyric[0]="And if I lived a thousand years you know I never could explain<br>The way I lost my heart to you that day...";
lyric[1]="I love you ‘cause I know that I can’t do anything wrong<br>You’re where I belong like red on a rose...";
lyric[2]="And I'm gonna make you a promise if there's life after this<br>I'm gonna be there to meet you with a warm, wet kiss...";
lyric[3]="In your eyes I see forever<br>Makes me wish that my life never knew<br>The day before you...";
var that = setTimeout(document.write(lyric[number]), 5000);
}
It prints out the lyrics and will change them when the page is refreshed but won't change them otherwise.
I know it's probably something easy, but I am a dolt when it comes to javascript.
Thanks!
Here is what I have:
Here is where I call the function...
<p>
<script>
<!--
getLyric();
//-->
</script>
</p>
Here is the function...
function randomNumber()
{
var ranNum= Math.floor(Math.random()*4);
return ranNum;
}
function getLyric()
{
var number=randomNumber();
var lyric=new Array(4);
lyric[0]="And if I lived a thousand years you know I never could explain<br>The way I lost my heart to you that day...";
lyric[1]="I love you ‘cause I know that I can’t do anything wrong<br>You’re where I belong like red on a rose...";
lyric[2]="And I'm gonna make you a promise if there's life after this<br>I'm gonna be there to meet you with a warm, wet kiss...";
lyric[3]="In your eyes I see forever<br>Makes me wish that my life never knew<br>The day before you...";
var that = setTimeout(document.write(lyric[number]), 5000);
}
It prints out the lyrics and will change them when the page is refreshed but won't change them otherwise.
I know it's probably something easy, but I am a dolt when it comes to javascript.
Thanks!