Results 1 to 3 of 3

Thread: Displaying a random text/picture/movie/song with one click?

  1. #1
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Displaying a random text/picture/movie/song with one click?

    Hello everyone. I'm relatively new to JavaScript. I've toyed a little with it...but I suppose that doesn't matter.

    I'm attempting to make a gift, sort of a random memory generator that'll pull up text and/or a picture and/or a movie and/or a song. I know it seems a little...much? But I'm having trouble trying to figure out how. I got the text part down, and I think I can do all of them...but not together. Here's the code I've been trying to work with.

    <DIV id="memorytext">Click the button below...</DIV>
    <IMG id="memory2" border="0">




    <script type="text/javascript">
    function rand ( n )
    {
    return ( Math.floor ( Math.random ( ) * n + 1 ) );
    }

    var our_memories = new Array ( );
    our_memories[0] = "If music be the food of love, play on";
    our_memories[1] = "When shall we three meet again...?";
    our_memories[2] = "What a piece of work is man!";
    our_memories[3] = "There's daggers in men's smiles";
    our_memories[4] = "Alas, poor Yorick! I knew him, Horatio";
    our_memories[5] = "Time shall unfold what plaited cunning hides";
    our_memories[6] = "Goodnight, goodnight! Parting is such sweet sorrow";
    our_memories[7] = "Friends, Romans, countrymen, lend me your ears";
    our_memories[8] = "I am dying, Egypt, dying";
    our_memories[9] = "Get thee to a nunn'ry";
    our_memories[10] = "Heya!";
    our_memories[11] = "<B>Get thee to a nunn'ry222222222222222</B> http://i5.tinypic.com/4le874k.gif";

    function pick_memory ( )
    {
    var DisplayText = our_memories[rand(12)-1];
    document.getElementById("memorytext").innerHTML = DisplayText;
    document.getElementById("memorypic").src = DisplayText;
    }
    </script>

    <form><input type="button" name="test" value="Click me" onclick="pick_memory ( )"></form>

    Any help would be appreciated...I've been toying with it for four hours now. ^^; I know, I suck. And ignore the random quotes on there...

  2. #2
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry for the double post. I think I got it working...

    <script type="text/javascript">
    function rand(n)
    {
    return (Math.floor(Math.random()*n));
    }

    var _memories = new Array(12);
    _memories[0] = "test0";
    _memories[1] = "test1";
    _memories[2] = "test2";
    _memories[3] = "test3";
    _memories[4] = "test4";
    _memories[5] = "test5";
    _memories[6] = "test6";
    _memories[7] = "test7";
    _memories[8] = "test8";
    _memories[9] = "test9";
    _memories[10] = "test10";
    _memories[11] = "test11";

    var _pic = new Array(3);
    _pic[0] = "emo1.png";
    _pic[1] = "emo2.jpg";
    _pic[2] = "emo2.jpg";

    function pick_memory()
    {
    var display = _memories[rand(12)];
    document.getElementById("memorytext").innerHTML = display;
    if (display == 5)
    {document.getElementById("memorypic").src = _pic[1]}
    else if (display == 10)
    {document.getElementById("memorypic").src = _pic[2]}
    else
    {document.getElementById("memorypic").src = _pic[0]}
    }
    </script>
    This works as far as the text, and initial picture goes. But it only, ONLY goes to the end ELSE statement for the picture. Other then that it never changes even when display is equal to 5. I'm stumped. ; ; Help! Thanks...

  3. #3
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Triple post. -.-

    I've got the scripts working to display pictures, text, and music flawless together, and able to change between all of them.

    <script type="text/javascript">
    function random(x)
    {
    return (Math.floor(Math.random()*x))
    }

    var _memories = new Array()
    _memories[0] = "test0"
    _memories[1] = "test1"
    _memories[2] = "test2"
    _memories[3] = "test3"
    _memories[4] = ""
    _memories[5] = ""
    _memories[6] = ""
    _memories[7] = ""
    _memories[8] = ""
    _memories[9] = ""
    _memories[10] = ""
    _memories[11] = ""

    var _pic = new Array()
    _pic[0] = ""
    _pic[1] = "emohug.jpg"
    _pic[2] = "remedy.mp3"

    var _multimedia = new Array()
    _pic[0] = ""
    _pic[1] = "remedy.mp3"

    function pick_memory()
    {
    var choice = random(4) /// -1 for actual memories posted, as 0 counts.
    document.getElementById("memorytext").innerHTML = _memories[choice]
    document.getElementById("memorypic").src = "b.jpg"
    document.getElementById("memorymulti").innerHTML = "<embed src='' height=24 width=275 autostart=false>"
    if (choice == 1)
    {document.getElementById("memorypic").src = "emohug.jpg"}
    else if (choice == 2)
    {document.getElementById("memorypic").src = "emobemypenguin.png"
    document.getElementById("memorymulti").innerHTML = "<embed src=remedy.mp3 height=24 width=275 autostart=false>"
    alert('time to rock baby!')}
    else if (choice == 3)
    {document.getElementById("memorypic").src = "b.jpg"
    document.getElementById("memorymulti").innerHTML = "<embed height=256 width=320 src=beowulf.mov type=video/quicktime pluginspage=www.apple.com/quicktime/download enablejavascript=true>"
    alert('movietime!')}
    }
    </script>
    Everything works fine but the last one. Embedding a movie. I know, there's a ton of different ways out on the internet...well...it shows it trying to load the movie but gives an error...much like it originally did with the mp3, but after tweaking some settings in firefox and the quicktime application, it worked for the mp3. But not so with MOV files.

    So now my question is this now. Is this method valid use for .mov files? Can it be used for .avi and .mpg files? Why's it giving me that plugin error when I just freshly installed it? (It works for going to apples site and checking the trailers, not here) Is the method I used for mp3 pretty stable? It seems to be...but I'm not sure, as I heard there's a lot of issues between the different browsers...

    Thanks for any help...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •