Forum Moderators: open

Message Too Old, No Replies

Image size

Image size as a variable

         

Adam5000

8:59 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Hello everyone. I've got another small project going and I need some help with it.

What I'm trying to do is set the width and height of an image as variables, and then change the size of the image by changing the value of the variables.

Below is my latest attempt but it doesn't work.

Help.

<html>
<head>
<title>Untitled</title>

<div id=Image1 style="position:absolute; left=0; top=0;">
<img src="Image 1.jpg"; width=a; height=b;>
</div>

</head>

<body>
<script language="javascript">
var a
var b
a=150
b=300
</script>
</body>
</html>

ChadSEO

9:50 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



You would want to do something like this:

<img src="images/myimage.gif" id="img1">

<script>
var img = document.getElementById("img1");
img.style.width=100;
img.style.height=40;
</script>

Dijkgraaf

9:56 pm on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why do you have a div and the image inside your head tags?
Neither of those two is valid.

<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id=Image1 style="position:absolute; left=0; top=0;">

<script type="text/javascript">
var a;
var b;
a=150;
b=300;
document.write('<img src="pagerror.gif" width='+a+' height='+b+'>')
</script>

</div>

</body>
</html>

Adam5000

11:28 am on Jul 31, 2005 (gmt 0)

10+ Year Member



Thanks to both of you and each script works great. I appreaciate your help.