Topic: how to get the height and width of the uploaded image using javascript

HI
  I want to put client validations to image before submit form.
so i want to get the height and width of the images into javascript
Am using

var img = document.getElementById('imageid');
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;

but its showing wrong dimentions.


can anybody help

Re: how to get the height and width of the uploaded image using javascript

Is the image being rendered to the page before you try and calculate its size?

Re: how to get the height and width of the uploaded image using javascript

var imgObj = document.getElementById('uploadedImage');
var newImg = new Image();
newImg.src = imgObj.attr('src');
var height = newImg.height;
var width = newImg.width;
imgObj.style.width = width;
imgObj.style.height = height;

You can use this code on your java script to get height and width of image.I hope this will work.Good luck.


Dating advice for women