-1

i got multiple input type file and i want to make a checking if the file max size exceeds the limit it clears the value of the input file. if i use the id if runs perfectly but when i change it to class i got error like this Uncaught ReferenceError: Invalid left-hand side in assignment... this is the script

<script src="https://code.jquery.com/jquery-2.1.4.min.js" ></script>
<input type="file" id="myFile2" class="upload" />
<input type="file" id="myFile1" class="upload" />
<input type="file" id="myFile3" class="upload" />


<script>
console.log("initiated");
var max_fileupload = 5899999;//5mb

$(".upload").bind('change', function(){
if(this.files[0].size > max_fileupload){
 alert("attachment file size is greater than maximum file size required");
 console.log($(this).val());
 $(this).replaceWith( $(this).clone( true ) );
}
});

</script>

is this possible using the class of the input file?

Julius Limson
  • 526
  • 9
  • 29

1 Answers1

1

Did you tried removing left side assignment, that causes the error?

 $(this).replaceWith( $(this).clone(true) );
Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69