Search code examples
javascriptrefreshmarquee

marquee text with change on refresh


I've been trying to get a javascript code for random text on refresh to work with the classic html marquee tag, is there a way of doing this? Putting it above the div gives me a whole moving paragraph but I want the text to scroll across the screen in sentence form, which only worked on the first sentence, then stopped working when on the others. Where can I insert this code so it will work? Thanks

<div>

<script language="JavaScript" type="text/javascript">// <![CDATA[
// <![CDATA[
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="<marquee behavior="scroll" direction="left">Text 1</marquee>"
myimages[2]="<marquee behavior="scroll" direction="left">Text 2</marquee>"
myimages[3]="<marquee behavior="scroll" direction="left">Text 3</marquee>"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<p>'+myimages[ry]+'</p>')
}
random_imglink()
// ]]]]><![CDATA[>
// ]]></script>

</div>

Solution

  • It will work need to clean up the code like

    myimages[1]='<marquee behavior="scroll" direction="left">Text 1</marquee>';
    myimages[2]='<marquee behavior="scroll" direction="left">Text 2</marquee>';
    myimages[3]='<marquee behavior="scroll" direction="left">Text 3</marquee>';
    

    your full code can be

    <div>
    <script language="JavaScript" type="text/javascript">
        function random_imglink(){
        var myimages=new Array()
        //specify random images below. You can have as many as you wish
        myimages[1]='<marquee behavior="scroll" direction="left">Text 1</marquee>';
        myimages[2]='<marquee behavior="scroll" direction="left">Text 2</marquee>';
        myimages[3]='<marquee behavior="scroll" direction="left">Text 3</marquee>';
    
        var ry=Math.floor(Math.random()*myimages.length)
        if (ry==0)
        ry=1
        document.write('<p>'+myimages[ry]+'</p>')
        }
        random_imglink()
    </script>
    </div>