Results 1 to 3 of 3

Thread: Help - Random Number script..

  1. #1
    Join Date
    Jun 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help - Random Number script..

    I'm not sure if this is working at all...
    I'm trying to get the iframe to display a different poem I've written each time the page is loaded or refreshed. Am I doing this right?
    Thank you for looking!!
    (There are poems in the real text documents I have, but it makes the file-size smaller without them in there...)


    Code:
    <html><body onload="ChangePoem()">
    
    <div style="text-align: center">
    
    <p style="color: blue">Message here<br /><br /></p>
    
    
    <table style="text-align: center; background-color: rgb(245, 225, 227);" border="1"
     cellpadding="5" width="100%">
    
    
    <!-- Random Poem --><tr>
    <td width="72%">
    <iframe id="Poem" src="Poem 1.txt" width="96%"></iframe>
    <script language="text/javascript">
    var Poem(3);
    var Last=3;
    Poem[0]="Poem 1.txt";
    Poem[1]="Poem 2.txt";
    Poem[2]="Poem 3.txt";
    function ChangePoem() {
    var ranNum = Math.floor(Math.random() * (lastPoem - startPoem)) + startPoem;
    document.getElementById ("Poem").location.href = Poem[ranNum];
    }
    </script>
    </td></tr>
    
    
    </table></div>
    </body></html>

  2. #2
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Wink Solution...

    My suggestion would be to use the following script that can be found here...
    http://www.dynamicdrive.com/dynamici...ndomiframe.htm

    I have tested this one and it works fine... Here is a copy of the code...

    Code:
    <html><body>
    
    <div style="text-align: center">
    
    <p style="color: blue">Message here<br /><br /></p>
    
    
    <table style="text-align: center; background-color: rgb(245, 225, 227);" border="1"
     cellpadding="5" width="100%">
    
    
    <!-- Random Poem --><tr>
    <td width="72%">
    <script language="JavaScript1.2">
    
    //Random iframe content- © Dynamic Drive (www.dynamicdrive.com)
    //For full source code, and Terms Of use, visit http://dynamicdrive.com
    //This credit MUST stay intact for use
    
    var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
    var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1
    
    //Specify IFRAME display attributes
    var iframeprops='width="97%" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'
    
    //Specify random URLs to display inside iframe
    var randomcontent=new Array()
    randomcontent[0]="Poem1.txt"
    randomcontent[1]="Poem2.txt"
    randomcontent[2]="Poem3.txt"
    
    
    //No need to edit after here
    if (ie||dom)
    document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')
    
    function random_iframe(){
    if (ie||dom){
    var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
    iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
    }
    }
    
    window.onload=random_iframe
    
    </script>
    
    
    </td></tr>
    
    
    </table></div>
    </body></html>
    If you notice that code writes the iframe from within the script itself instead of using one that is already written into the HTML. Hope this helps.
    Last edited by TheJoshMan; 11-11-2006 at 11:03 AM.

  3. #3
    Join Date
    Jun 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thank you!

    Thank you, that works!! ^_^ I very much appreciate your 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
  •