1

I follow the suggestion from Find size of file behind download link with jQuery for the file size checking and added return false; to prevent form submission, but failed. The code as following:

 function findSize() {
  var fileInput = $("#loadfile")[0];
  if (fileInput.files[0].fileSize > 1048 ) {
    alert(fileInput.files[0].fileSize);
    return false;
  }
 }

<input type="submit" value="Submit" class="form-submit" onclick="findSize()" />

How do I prevent form submission when file size over limit?

Community
  • 1
  • 1
Peter
  • 1,481
  • 4
  • 19
  • 37

1 Answers1

1

putting you check in the onsubmit of the form instead of the onclick of the submit-button should solve this.

oezi
  • 51,017
  • 10
  • 98
  • 115
  • I tried the onsubmit but still the submission go through. Any other suggestion? – Peter Jan 13 '11 at 07:40
  • Sorry my mistake, I should have put the onsubmit on the form instead on the button. It works now! Thank oezi. – Peter Jan 13 '11 at 07:59