Web Analytics Made Easy -
StatCounter Javascript random image help - CodingForum

Announcement

Collapse
No announcement yet.

Javascript random image help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript random image help

    Hey all i need the following script to have the <script type="text/javascript">changeslides("initial")</script> to have a random number (in this example of mine, its 0-4) So either 0,1,2,3 or 4 would load up on every refresh of the site.

    Also, could someone also be great to see if i can mod the GoBack/GoForward commands to loop back around to the first image once it reaches the end of the slideshow?
    Code:
    <script type="text/javascript">
    <!--
    // Index It Image Slideshow script- By JavaScriptKit.com
    // For this and over 400+ free scripts, visit JavaScript Kit- [url]http://www.javascriptkit.com/[/url]
    // This notice must stay intact for use
    //Specify images for slideshow:
    //["Image Path", "Optional Image link"]
    
    var numberslide=new Array()
    numberslide[0]=["images/MP1_15.jpg", "http://www.google.com"]
    numberslide[1]=["images/MP2_15.jpg", ""]
    numberslide[2]=["images/MP3_15.jpg", ""]
    numberslide[3]=["images/MP4_15.jpg", ""]
    numberslide[4]=["images/MP5_15.jpg", ""]
    
    var mylinktarget=""
    var mylinkcolor="navy"
    var mylinkcolorSelected="red"
    var imgborderwidth=0
    var preloadit=new Array()
    for (i=0;i<numberslide.length;i++){
    preloadit[i]=new Image()
    preloadit[i].src=numberslide[i][0]
    }
    
    var currentindex=""
    
    function changeslides(which){
    var imghtml=""
    currentindex=(which=="initial")? 0 : parseInt(which)
    var mode=(which=="initial")? "initial" : ""
    var which=(mode=="initial")? numberslide[0] : numberslide[which]
    if (which[1]!="")
    imghtml='<a href="'+which[1]+'" target="'+mylinktarget+'">'
    imghtml+='<img src="'+which[0]+'" border="'+imgborderwidth+'">'
    if (which[1]!="")
    imghtml+='</a>'
    
    if (mode=="initial")
    document.write('<div>'+imghtml+'</div>')
    else{
    document.getElementById("imagecontainer").innerHTML=imghtml
    changecolors()
    }
    }
    
    function createnumbers(){
    document.write('<a href="javascript:changeslides(0)" style="color:'+mylinkcolorSelected+'">0</a> ')
    for (i=1; i< numberslide.length; i++)
    document.write('<a href="javascript:changeslides(\''+i+'\')">'+i+'</a> ')
    }
    
    function changecolors(){
    var numberobj=document.getElementById("numberDiv")
    numberlinks=numberobj.getElementsByTagName("A")
    for (i=0; i<=currentindex; i++)
    numberlinks[i].style.color=mylinkcolorSelected
    for (i=currentindex+1; i<numberslide.length; i++)
    numberlinks[i].style.color=mylinkcolor
    }
    
    function goforward(){
    if (currentindex<numberslide.length-1)
    changeslides(currentindex+1)
    }
    
    function goback(){
    if (currentindex!=0)
    changeslides(currentindex-1)
    }
    //-->
    </script>
    Thank you for your time!
    David

  • #2
    ummm, anyone??

    David

    Comment

    Working...
    X