I am calling a JavaScript function where I want to validate image height and width before uploading. I return `false` value but in the source function when it is console log it gives `undefined`.

For better understanding please check the code. The code is running well but I want to get `true` and `false` from the JavaScript functions.

```js
$(document).on('change', '#userfile', function() {
  var result = ValidateAuthorImage(event, $(this));
  console.log(result);
});

function ValidateAuthorImage(event, obj) {
  var files = event.target.files;
  var valid = true;
  var height = 0;
  var width = 0;
  var _URL = window.URL || window.webkitURL;

  for (var i = 0; i < files.length; i++) {
    var img = new Image();
    img.onload = function() {
      height = img.height;
      width = img.width;
      //alert(width + " " + height);
      if (width < 700 || height < 500) {
        $("#msg_upload").html('<span style="color:red;">Please uplaod image with at least width = 700 and height  = 500 </span>');
        obj.value = "";
        return false;
      } else {
        $("#msg_upload").html('');
      }
    }
    img.src = _URL.createObjectURL(files[i]);
  }
}

```