0

Why did you select an image twice the size of the second order image is not showing?

My full code: http://jsfiddle.net/ayxZM/

<script type="text/javascript">
    function handleFiles(files) {
        for (var i = 0; i < files.length; i++)
        {
            alert(files[i].size + " Bytes");
        }
    }
</script>
<input type="file" onchange="handleFiles(this.files)">​

4 Answers 4

1

If you select the same image twice then the image selection hasn't really changed, so the onchange handler isn't fired. If you select a different image its size is displayed.

Sign up to request clarification or add additional context in comments.

2 Comments

I select the same image twice, What do i do?
Why do you need to do anything? You've already done something with that image's details the first time...
0

Reset your field like this. I tested it. It works perfectly.

            <script type="text/javascript">

                function handleFiles(files) {
                    for (var i = 0; i < files.length; i++)
                    {
                       alert(files[i].size + ' Bytes' );
                       reset_field('handleFilesfield');
                }
                }

                function reset_field(id) {
                $('#'+id).html($('#'+id).html());
                }

            </script>
            ​<form>
                <span id="handleFilesfield"><input type="file" onchange="handleFiles(this.files)"/></span>
            </form>

2 Comments

What if the value needs to be retained so that it can be submitted?
Well then just save it somewhere while inside handleFiles. You can even assign it to another form field in your page, so you can retain it. At least, your value will not be associated with your file input.
0

Because when you click on the same image, the second time, there is no change of file, so the onchange event does not get triggered, so the function handleFiles does not get called, so the size does not get displayed. Use another event for this case. Maybe you could reset the input file inside the handleFiles function. That way, even if the user selects the same image again, it will be considered as a new image, and therefore the onchange event will get triggered.

Comments

0

As mentioned here already: onchange does not fire when you select the same image (= don't change the value – see? that makes sense). But if you want to fire onchange everytime you can try reseting the value in onmousedown event. That way the value stays for submission and also forces onchange to fire. Demo: http://jsfiddle.net/LeZuse/ayxZM/27/
NOTE: If you need it to be touch compatible, you may wanna use ontouchstart also.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.