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

  • Home
  • SEARCH
  • 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 8713353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:19:24+00:00 2026-06-13T05:19:24+00:00

I am relatively new with javascript and as such, my code to get a

  • 0

I am relatively new with javascript and as such, my code to get a random image to show up when my page loads is not working. I have looked at a few examples to try and solve the problem, but after a few hours of searching I am ready to press the help button. I have included the HTML and script for my page. Additionally, I have commented the IMG tag I am trying to manipulate.

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome in.</title>
<link href="home.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="slides.js"></script>
<script>
//This is where I am attempting to set an random image to load.
function()
{   
    //Array of quotes
    var randomImages= new Array ("Images/quote1.png", "Images/quote2.png","Images/quote3.png", "Images/quote4.png", "Images/quote5.png","Images/quote6.png","Images/quote7.png","Images/quote8.png");

    //Random number to select an image. Use 8, not 7, since javascript arrays are 0 based
    //Math.floor will take us from a floating point number to an integer base
    var randomNumber = Math.floor(7*Math.random());


    //Display that image
    document.getElementById('quoter').setAttribute('src',randomImages[randomNumber]);
}
</script>
</head>
<body onLoad="function()">
<a href="aboutme.html" id="aboutMe"><img src="Images/aboutme.png" alt="aboutme"/></a>
<a href="aboutme.html" id="contact"><img src="Images/contact.png" alt="aboutme"/></a>
<a href="aboutme.html" id="blog"><img src="Images/blog.png" alt="aboutme"/></a>
<a href="aboutme.html" id="wife"><img src="Images/mywife.png" alt="aboutme"/></a>
<div id="mid">
</div>
<div id="slideshow">
   <div>
     <img src="Images/dummypic.png" alt="me">
   </div>
   <div>
     <img src="Images/dummypic2.png" alt="me">
   </div>
   <div>
     <img src="Images/dummypic3.png" alt="me">
   </div>
</div>
<div>
<img id="quoter" src="" alt="quotes"> <!--This is what I am trying to make random when the page loads-->
</div>
</body>
</html>
  • 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-06-13T05:19:26+00:00Added an answer on June 13, 2026 at 5:19 am

    Provide a name to your function.

    It can not be function(), It should be like function function_name() and then use it on body onLoad like <body onLoad="function_name()">

    As you have included jquery-1.7.1.min.js, you can try this code, and you should remove body onload attribute.

    $(function(){
        //Array of quotes
        var randomImages= new Array ("Images/quote1.png", "Images/quote2.png","Images/quote3.png", "Images/quote4.png", "Images/quote5.png","Images/quote6.png","Images/quote7.png","Images/quote8.png");
    
        //Random number to select an image. Use 8, not 7, since javascript arrays are 0 based
        //Math.floor will take us from a floating point number to an integer base
        var randomNumber = Math.floor((randomImages.length-1)*Math.random());
    
        //Display that image
        $('#quoter').prop('src',randomImages[randomNumber]);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to X Code and I m working on photo collage App
I'm relatively new with WordPress theming and JavaScript, though not incompetent with either. I'm
I'm relatively new to web programming. New to Javascript, PHP, Ajax, etc. I have
I am relatively new to javascript. I am trying to code my web version
I am relatively new to JavaScript. I have developed an application with the Outsystems
I am relatively new to programming with PHP. I have created a simple Javascript
I am relatively new to javascript and I am facing some difficulty.I have two
I'm relatively new to javascript so please hold it against me. I have a
Hi I am relatively new to jQuery and JavaScript and have a question regarding
I'm relatively new to javascript and am building a web page. I'm using 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.