0

Ok, I have multiple file inputs in my app. I try to get file API for each of them, but I get the unidentified error.

My code is in HTML

 <div>
            @if(isset($images[$i]))

            <img src="{{ asset('profilepics/'.$images[$i]->name) }}" class="img-thumbnail"  width="104" height="36"   />
                @else
                <img src="{{ asset('profilepics/select_image.png') }}" class="img-thumbnail"  width="104" height="36"   />
            @endif
            <input type="file" class="fu" data-id="{{$i}}" name="image_file_{{$i}}" id="image_file_{{$i}}"  />
        <div>

Js code is

$('.fu').click(function(){
    var x = $(this).data('id');

    fileSelectHandler(x);
});

function fileSelectHandler(x) {


    var oFile = $('#image_file_'+x).files[0];
    ...

But in var oFile, I get error unidentified error. My using of files[0] probably it's wrong. Any solution

2
  • Please inspect one of your images, and provide the HTML that's been generated. Commented Feb 4, 2016 at 13:00
  • tnx solved with answer below pls vote up Commented Feb 4, 2016 at 13:03

1 Answer 1

1

If you need to use files[] you need to put the pure-javascript DOM object, not the jQuery object. You can achieve that only adding .get(0) to retrieve the DOM object:

var oFile = $('#image_file_'+x).get(0).files[0];
Sign up to request clarification or add additional context in comments.

1 Comment

hello are you online to help me

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.