I have a picture item in my application. I want to restrict the image filesize and show an alert like "your filesize can be maximum 2MB" .
I tried it with the java-script below it show only the alert but don't restrict the size.
var oFile = document.getElementById("P231_PIC").files[0]; // <input type="file" id="P231_PIC" accept=".jpg,.png,.gif,.jpeg"/>
if (oFile.size > 2097152) // 2 mb for bytes.
{
alert("File size must under 2mb!");
return;
}
it should be like below when I choose more then 2mb.

I will be very grateful if anyone help.