title: How to get image size of a form field (formData) in Javascript
body: <p>Any idea how to get size in bytes of an image within a validating javascript function so that user will be prompted to pick a valid image size. I have seen other answers which handle this out of the form logic, but I want to know if I can get the size within the validation javascript function. Thanks</p>
  <p>Here is my Form related code:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form action=&quot;index.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; onsubmit=&quot;return validateForm(this)&quot;&gt;
      &lt;script&gt;
          function validateForm(form) {
              var image_name = form.image.value;
              if (image_name == null || image_name == &quot;&quot;) {
                  alert('Select an image');
                  return false;
              } else return true;
          }
      &lt;/script&gt;
      &lt;label&gt; Image (300 KB max.) &lt;input type=&quot;file&quot; name=&quot;image&quot; /&gt; &lt;/label&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submit&quot; /&gt;
  &lt;/form&gt;
  </code></pre>