I am having a file upload form where I am checking the file size through javascript before finally submitting the form. The form is working fine and when I try to upload a file more than the mentioned size then it shows the correct alert at the first time. But if I again click on upload without selecting another file I get the same alert twice. If I again repeat the process I get the alert 3 times. Below is the code
<script>
var flag=0;
$('#filename').bind('change', function() {
var filesiz = this.files[0].size;
if (filesiz >10485760)
{flag=1;}
else
{flag=0;}
});
function upfunc(){
$('#smalldata').hide();
$('#invalidfile').hide();
$('#invalidfile9').hide();
if($( "#UserComments" ).hasClass( "textAreaField valid" ) && $( "#filename" ).hasClass( "valid" )){
$('#loading_image').show(); // show animation
$( "#uploadsfrm" ).submit(function() {
if(flag==1)
{alert ('File size cannot exceed 10 MB.');
$('#loading_image').hide();
return false;
//event.preventDefault();
}
else
return true;
});
}
}
</script>
I think the error may be because I am using bind. Any help would be really appreciated.Thank you