title: Validate the image upload with size, height and width
body: <pre><code>function displayPreview(files) {
  
      var reader = new FileReader();
      var img = new Image();
      reader.onload = function (e) {
          img.src = e.target.result;
          fileSize = Math.round(files.size / 1024);
          if(fileSize&gt;50) {
              ret1=false;
              alert("File size is " + fileSize + " kb");
              return ret1;
          } else  {
              var ret1 = true;
              return ret1;
          }
      img.onload = function () {
          if(this.width!="181" &amp;&amp; this.height!="181") {
              ret1=false;
              alert("width=" + this.width + " height=" + this.height);
              return ret1;
          } else  {
          var ret1 = true;
          return ret1;
          }
          console.log("width=" + this.width + " height=" + this.height+"File size is " + fileSize + " kb");
      };
  };
      reader.readAsDataURL(files);
  }   
  function chkform() {
      var ret = false;
          if (document.getElementById("file").value === "") {
              console.log("empty");
          } else  {
              var file = document.getElementById("file").files[0];
              var tt=displayPreview(file);
              console.log(tt+"nis");
          }
          return ret;
  }
  </code></pre>
  
  <p>When a user clicks on the submit button, the form has an <code>onsubmit="return chkform();"</code>, then my <code>checkform</code> checks if the id name <strong><code>file</code></strong> is empty or not.</p>
  
  <p>If not, then it call the function <code>displayPreview()</code>. In that function I am checking whether the size is not more than 50 and width and height is not equal to <code>width="181px"</code> and <code>height="181px"</code>. </p>
  
  <p>I am returning ret through which I can get the information it's returning true or false 
  but In my <code>checkform</code> I am getting <strong><code>UNDEFINED</code></strong>... why?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Added reproduction code at JSFIddle: <a href="http://jsfiddle.net/nishit_bhardwaj/zaukV/" rel="nofollow">http://jsfiddle.net/nishit_bhardwaj/zaukV/</a></p>