Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out line in Javascript

Tags:

javascript

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>
like image 359
user2514364 Avatar asked Jul 10 '13 19:07

user2514364


1 Answers

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.

like image 71
Peter Rasmussen Avatar answered Sep 21 '22 03:09

Peter Rasmussen