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 8501281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:10:07+00:00 2026-06-11T01:10:07+00:00

Here is the problem I put to you. I have an page where a

  • 0

Here is the problem I put to you.

I have an page where a random image is placed using some hand written Javascript code. the premise is that the images are all different sizes.

Now I want to display the image so that either it takes up most of the screen ( style=” width: 95%;” ) or that the image doesn’t resize higher then it’s own maximum size. So in essence the image is always fully displayed fully (horizontally at least).

What i don’t want to do is hardcode anything but the image locations. So I want to dynamically somehow fetch the max sizes and force the page to recognize them.

I’ve been looking at finding Javascript (and JQuery by suggestion) functions and CSS code to manage what I am looking for, but to no avail. Part of the problem may be me not finding a reliable readable source, having learnt some stuff in school but honestly not having a proper clue for what I am looking for. And right now I seeing my options I feel like what I ask cannot be done.

However I pose the problem here. And also paste the code I had so far. Any suggestions, alterations and help is welcome. I don’t know and can’t find it.

<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<script type="text/javascript" src="./js/jquery-1.8.1.min.js">
<script type="text/javascript">
var links = ['./img/1-teech.png', './img/2-slingshot.png', './img/3-upright.jpg', './img/4-drawing.png', './img/5-wing.png', './img/6-flying.png', 'img/7-filly.png'];
var credits = ['Pencils', 'Pencils', 'Eljordo', 'Ezynell', 'Laydee Kaze', 'Yu Chie', 'Honey Puff'];
function setRandomImage()
{
setImage(getRandomInt(links.length - 1));
}

function setImage(var i)
{
document.getElementById('tichimage').src = links[i];
document.getElementById('credits').innerHTML = credits[i];
}

function getRandomInt(max)  
{  
  return Math.floor(Math.random() * (max + 1));  
} 
</script>
</head>

<body>
<p align="center"><img src="" alt="Tich" style=" width: 95%;" id="tichimage"/></img>     <br /></p>
<p align="center">By <span id ="credits"></span></p>
<p align="center"><img src="./img/random-button.png" alt="Random Image" onclick="setRandomImage()"/></p>
<script type="text/javascript">
setRandomImage();
</script>
</body>
</html>

I realize that not everything I am doing is exactly 100% to web standards, but ehhhhh. It was designed as more of a test page for me to do stuff in, all the previous stuff I did myself a little. but the thing I want now seems too difficult. And I don’t know where to go.

Thanks for helping

  • 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-11T01:10:09+00:00Added an answer on June 11, 2026 at 1:10 am

    Here’s a working example that will capture the height and width of the image and assign it to a variable: http://jsfiddle.net/charlescarver/BrwAj/2/

    var img = new Image();
    img.src = $("#tichimage").attr("src");
    img.onload = function() {
        var width = this.width;
        var height = this.height;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with a Google Maps page I have put together.
I have put together a small example here just to replicate the problem. I
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I have a problem here im trying to upload a file first time it
What is the problem here? (Besides having redundant code). $.getJSON works as expected. However
I have a problem here. My Zend_Forms do not render in view script. Via
I have a problem here I can't solve. I have a database of houses
enter code here My problem is this: in this database the junction table contains
I have simplified my page and here what I have: <html> <head> <meta http-equiv=content-type
I have a problem with site deployed on IIS6 sever. Here the problem, when

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.