I want to test the return value of this function getFileExtension(input.files[0].name) (I have a comment there to point at that line) My question is how to print out that value in javascript? Thanks!
<script>
function getFileExtension(filename) {
var ext=filename.split('.').pop();
return ext
}
</script>
<input type='file' onchange="readURL(this);">
<script>
function readURL(input) {
if (input.files && input.files[0]) {
if (getFileExtension(input.files[0].name)=="png") { // this line is our problem
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById("pdf").innerHTML="<img id='blah' src=" +
e.target.result + " alt='your image' width='450'>"
}
reader.readAsDataURL(input.files[0]);
}
}
}
</script>
You can print out values in javascript by writing
console.log(value);
Most browsers have a console which you can see by pressing f12
. The values will end up there.
If you are using Internet explorer remember to have developer tools open (f12) or you will get an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With