I want to check the image size in JavaScript.. for example if image size is more than 500kb and other format instead of jpg.. it should not get uploaded.. i want to check these validation before form submit..

thanks in advance..

waiting for positive ans.

Regards

A solution is offered HERE (see Rodboy's post part way down the page).

I have not tested the code but on first inspection it appears to be an honest offering. It is dated 2007 so may be no longer valid. Note the in-code comment to the effect that file size detection is not guaranteed, therefore javascript would only be a first line of defence; a server-side accept/reject check would also be necessary.

Airshow

I want to check the image size in JavaScript.. for example if image size is more than 500kb and other format instead of jpg.. it should not get uploaded.. i want to check these validation before form submit..

thanks in advance..

waiting for positive ans.

Regards

This will do your thing on all versions of Explorer.

<input type=file id=fileUp onchange="getImg()">
<img id=imgProbe src="" style="width:100px; display:block">
<script>
getImg=function(){
	imgProbe.src=fileUp.value;
	imgProbe.onload=function(){
		(imgProbe.fileSize/1024)>500?
		alert("500KB Exceeded!"):imgProbe.mimeType.match(/jpeg/i)?
		1:alert("JPG Required!")
		}
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.