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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Splitting up a random image/link/text script

    This is a very basic javascript queestion - so apologies in advance.

    I currently have a perfectly working random image/link/text script. For the last day or so, I've been trying to split up the Arrays to generate linked results, but in different places.

    By that, I mean I'd like to display the image/link arrays in one div, and the text array in a completely separate div. I assume I have to split up the document.write(...) part of the script, but I can't seem to do it without killing the entire operation. The script in questions is below:

    Code:
    <div>
    <script language="JavaScript">
    <!--
    
    function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish
    myimages[1]="1.gif"
    myimages[2]="2.gif"
    
    //specify corresponding links below
    var imagelinks=new Array()
    imagelinks[1]="1.gif"
    imagelinks[2]="2.gif"
    
    var text = new Array()
    text[1] ="share: 1"
    text[2] ="share: 2"
    
    var ry=Math.floor(Math.random()*myimages.length)
    if (ry==0)
    ry=1
    document.write('<a target="_blank" href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a><div class="linkbox">'+text[ry]+'</div>')
    }
    random_imglink()
    //-->
    </script>
    </div>
    
    <div class="linkbox">-THIS IS WHERE I'D LIKE THE TEXT ARRAY TO APPEAR-</div>
    Is what I'm asking even possible? Can you split up arrays and still produce linked results?

    Thanks in advance!

  • #2
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You Sir, are a gentleman and a scholar; it worked perfectly. Thank you for your help. I'll also make sure I use type="text/javascript" from now on!


  •  

    Posting Permissions

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