Select an element of form field from an array of fields

Select an element of form field from an array of fields

Hi everyone
I have a form with an array of field, like this

<div class="thumbnail">
         <img id="photoimg[]"   name="photoimg[]"   src="<?php echo $photo[0];?>"

<div class="thumbnail">
         <img id="photoimg[]"   name="photoimg[]"   src="<?php echo $photo[1];?>"

<div class="thumbnail">
         <img id="photoimg[]"   name="photoimg[]"   src="<?php echo $photo[3];?>"

...... and so on.....................

I wish to update photo while i press "browse" button, something such:

  <input type="file" name="filefotoload[]"                          
                              id="filefotoload[]"                          
                              class="btn btn-success"
                              accept="image/gif, image/jpeg, image/png, image/JPG"
                              onchange="readURL(this);" >

this is a jquery script that works fine without using an html array field (field name photoimg without brackets)

<script>
function readURL(input) {
if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            $('#photoimg').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#photoimg'").change(function(){
    readURL(this);
});
</script>

How can change following statment

            $('#photoimg').attr('src', e.target.result);

to

            $('#photoimg')[indexnumber].attr('src', e.target.result); (indexnumber=Pointer to a specific photo, passed to function such function readURL(input,indexnumber) )

I tried but doesn't work, passing to function number of element of array, I hope to be explain myself good
Thank You very much in advance for yours replies