1
<script type="text/javascript">
    function ValidateSize(file) {
            var FileSize = file.files[0].size / 1024 / 1024; // in MB
            if (FileSize > 2) {
                alert('File size exceeds 2 MB');
                $(file).val(''); //for clearing with Jquery
            } else {

            }
        }
        </script>
     <input onchange="ValidateSize(this)" type="file" id="file">

Here is the code. I desire that if the image size is greater than 2 mb, the image should not append but clear from file. Any help please.

  • 1
    Your code seems OK, what is the problem exactly when you try it? – Timothé Malahieude Sep 19 '17 at 08:10
  • I noticed i was trying it out from html but when i tried from visual studio the worked just fine. Thank you. Still i dont know why i was not getting the result on html but anyway. its fine now. thank you – Martin Odongo Sep 22 '17 at 12:57

0 Answers0