I have this script which work (not in the if part) to check a picture dimension. the picture have to under 300x300 and this script always return false (even for 100x100 picture)
function validate_dimention(fileName) {
    input = document.getElementById("profilepic");
    file = input.files[0];
    var reader = new FileReader();
    var image = new Image();
    var width;
    var height;
    reader.readAsDataURL(file);
    reader.onload = function(pic) {
        image.src = pic.target.result;
        image.onload = function() {
            width = this.width; //panjang
            height = this.height; //lebar
        }
    }
    if (width <= 300 && height <= 300) {
        return true;
    } else {
        console.log(width);
        console.log(height);
        return false;
    }
}
the console log always return both as undefined (so the code have no syntax eror),, is there a way so width equals to //panjang and height equals to //lebar??
 
     
     
    