Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post

    How can I rotate random options?

    I'm working on a small scrolling popup window that mimicks an instant message window. I've currently got it all set up and working however I would like a way to have multiple var html_code options that can be picked at random. For example, each option would have a different image and text in the box.
    Here's the header code:
    (header code)
    <LINK REL=StyleSheet HREF="scrolling_popup.css"

    TYPE="text/css">
    <script type="text/javascript" language="javascript"
    src="scrolling_popup.js"></script>
    <script type="text/javascript" >

    var html_code = '<table border="0" width="100%"<tr><td valign="top"><img
    src="http://www.oohya.net/im.jpg" width="62"
    height="77"></td><td valign="top">Hey we live close to
    each other.<br>Wanna hook up?<br><br><a
    href="http://www.oohya.org"
    target="_blank">Reply</a></td></tr></table>';
    buildPopup_HtmlCode(200, 140, 'IM from:
    sweetlips21', html_code);
    </script>

    Here's the footer code:
    (footer code)
    <script type="text/javascript" >
    setTimeout("ShowTheBox(true, rightSide, bottomCorner, bottopUp)",30000);
    </script>

    Any help on how to accomplish this would be great.

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    can you link the entire page or paste the code?

    put your different options for the var html_code into an array

    var array=new Array()
    array[0]="the html code"
    array[1]="the next html code"

    then to switch the html use it like this. you want to change it to the first html option
    for instance if you want an onclick event

    <a href="#" onClick="switch(0)">switch</a>


    function switch(num){
    document.getElementById("someID").innerHTML=array[num]
    }

    besure to rename someID to the actual name of your element.
    You want to use Math.random(array.length) to make your random number.

    be sure to google for tutorials or working scripts if you need more help

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post
    Thanks TinyScript.
    I knew that I needed to set up an array but I guess what I'm not exactly sure of is how to incorporate the var html_code and how to set it up with the current trigger that is placed in the footer of setTimeout("ShowTheBox(true, rightSide, bottomCorner, bottopUp)", 30000);.

    If it were just a regular pop up window it wouldn't be an issue, but using the java scroll box with the html encased in it I guess I'm little unsure of how to encase the java within the java if that makes sense.

    I'm assuming that it would need to look something like this, please don't hold back on all that is wrong with this:

    var array=new Array()
    array[0]="var html_code = '<table border="0" width="100%"<tr><td valign="top"><img src="http://www.oohya.net/im.jpg" width="62" height="77"></td><td valign="top">Hey we live close to each other.<br>U single?<br><br><a href="http://www.oohya.org" target="_blank">Reply</a></td></tr></table>';"
    buildPopup_HtmlCode(200, 140, 'IM from: sweetlips69 F/23', html_code);

    array[1]="var html_code = '<table border="0" width="100%"<tr><td valign="top"><img src="http://www.oohya.net/im2.jpg" width="62" height="77"></td><td valign="top">Hey you don't live very far from me.<br>R U single?<br><br><a href="http://www.oohya.org" target="_blank">Reply</a></td></tr></table>';"
    buildPopup_HtmlCode(200, 140, 'IM from: nicecookies F/29', html_code);

    <a href="#" onLoad="switch(0)">switch</a>

    function switch(num){
    document.getElementById("someID").innerHTML=array[num]
    }

    Math.random(array.length);

    </script>

    What would be my element id though, var html_code?
    I'm probably way off track on the whole thing.


  •  

    Posting Permissions

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