Help with Image()

Basically what I’m trying to do is get an image to display using JavaScript. I’m using the code below and of course it’s not working. I have no idea why, but all that is displayed is the location of where the image is. I’ve tried different variations of this code with no luck. Can anyone help out? Thanks!

<script type=“text/javascript”>
function car (image) {
var image = new Image();
image.src = “ta.jpg”;
document.write(image.src);
}
</script>

<body onLoad=“car()”>

</body>

FYI… I’m using a JavaScript page and the file is saved as .htm, this is why there’s no header or html tags.

It worked like a charm! Thank you again!

Okay. I’ll give this a try! Thanks!

No need for the onload function if you don’t want to wait for the image to load before displaying. i.e.


var image = new Image();
image.src='someimage.jpg';
document.body.appendChild(image);

should work as well…

You need to insert the actual image object. i.e.


var image = new Image();

image.onload = function()
{
    document.body.appendChild(image);
}

image.src='someimage.jpg';