469,348 Members | 1,305 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,348 developers. It's quick & easy.

validate image dimension in IE7

function validateImageDimension(path, expectedWidth, expectedHeight) {
var img = new Image();
img.src = path;
return (img.width == expectedWidth && img.height ==
expectedHeight);
}

function uploadCustomerLogo() {
var customerLogoFilePath =
document.getElementById("customerLogoFile").value;
if (!validateImageDimension(customerLogoFilePath, 160,
160)) {
alert('wrong size');
return;
}

I have this javascript to validate image dimension before uploading.
It was working fine in IE6. But it doesn't work anymore in IE7.
Because the image width and height is return as 0.

Anyone has idea how to fix this? Or a better way to do this?

Thanks

Mar 1 '07 #1
1 1514
ASM
Josee a écrit :
function validateImageDimension(path, expectedWidth, expectedHeight) {
var img = new Image();
img.onload = function () {
return ( img.width == expectedWidth &&
img.height == expectedHeight )
}
img.src = path;
}

function uploadCustomerLogo() {
var customerLogoFilePath =
document.getElementById("customerLogoFile").value;
if (!validateImageDimension(customerLogoFilePath, 160,
160)) {
alert('wrong size');
return;
}


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ruby Tuesday | last post: by
1 post views Thread by John | last post: by
2 posts views Thread by emma.sax | last post: by
3 posts views Thread by Danny Ni | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.