Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3619148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:50:32+00:00 2026-05-18T22:50:32+00:00

i want to create a random image and its url, i mean not the

  • 0

i want to create a random image and its url, i mean not the link of the image, but in addition to image’s link, i want the specified URL, so that random image was displayed and when u click on it, u go to the specified URL

here is my javascript:

    function random_imglink(){
      var myimages=new Array()
      //specify random images below. You can have as many as you wish
      myimages[1]="/documents/templates/projedepo/banner/canon.jpg"
      myimages[2]="/documents/templates/projedepo/banner/indigovision.jpg"

      var ry=Math.floor(Math.random()*myimages.length)

      if (ry==0)
         ry=1

    var randomImage = '<img src="'+myimages[ry]+'" height="420" width="964" />';
    document.getElementById("image2").innerHTML = randomImage;
    }
    random_imglink()

Here is my HTML:

<div id="slider_container">    
<div id="image2">
</div>
<div id="thumb2">
<a href="#" rel="/documents/templates/projedepo/banner/canon.jpg" class="image2" ><img title="Canon" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t1.png" border="0"/></a>
<a href="#" rel="/documents/templates/projedepo/banner/indigovision.jpg" class="image2"><img title="IndogoVision" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t2.png" border="0"/></a>
</div></div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:50:33+00:00Added an answer on May 18, 2026 at 10:50 pm

    I’m not entirely sure what you want to do, but I think you want to create a single image which links to an url, chosen at random from a list of images and corresponding urls. You could do it like this:

    function random_imglink() {
        var myimages = [
            {image: "/documents/templates/projedepo/banner/canon.jpg", url: "http://www.url1.com"},
            {image: "/documents/templates/projedepo/banner/indigovision.jpg", url: "http://www.url2.com"}
        ];
    
        var ry=Math.floor(Math.random()*myimages.length);
    
        var randomImage = myimages[ry];
    
        var randomImageLink = '<a href="' + randomImage.url + '"><img src="'+randomImage.image+'" height="420" width="964" /></a>';
        document.getElementById("image2").innerHTML = randomImageLink;
    }
    

    I’m using [] here to create an array, which starts at index 0 (see: http://www.hunlock.com/blogs/Mastering_Javascript_Arrays). Because of this, you don’t need the if (ry == 0) ry = 1; part. The things in {} are javascript objects, which you can use as associative (key-value) arrays. See also http://www.quirksmode.org/js/associative.html.

    Maybe you already know all of this, in which case please disregard everything I said 🙂

    EDIT:

    By the way, if you want to do this a little bit nicer and there will always be an image and a link in your image2 div, you could put all the non-dynamic stuff in the html:

    <div id="image2">
        <a id="image2-link" href="#"><img id="image2-image" src="" height="420" width="964" /></a>
    </div>
    

    and then

    (...)
    
        var randomImage = myimages[ry];
    
        document.getElementById("image2-link").href = randomImage.url;
        document.getElementById("image2-image").src = randomImage.image;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to quickly create some random image with the icon size? I don't want
I want to create a random number function but I don't want to use
I want to create a Qt application that takes a random integer and sends
I want to create a random color from rgb(r,g,b) and want to display its
In my constructor, I want to create a random color. Therefore, I need three
For an online game (MMORPG) I want to create characters (players) with random strength
Why do i need to create an instance of Random class, if i want
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass
I build my action for create image thumbs, and I want add to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.