It's really good practice to pack your logical component into a single DOM node. The way you have it structured, there's no logical connection between the image and the input, other than the fact that one is beside the other. Simply because Sheila sits in the cubicle beside mine doesn't mean we're functioning together.
Instead, see what I've got below -- each image/input is contained in a div. The only image that an input should see is right in its same container. Now Sheila is in the same cubicle as me, we're now working on the same thing and can reference each other.
And, rather than the image and the input needing to know about each other, I'm asking the container itself to set those values. By doing this, the pieces are a little more loosely coupled.
var containerEls = $(".container");
containerEls.each(function(){
var imgEl = $(this).find("img");
var inputEl = $(this).find("input[type=text]");
inputEl.val(imgEl.attr("src") );
});
input {
width: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div>
<img src="http://via.placeholder.com/350x150">
</div>
<input type="text">
</div>
<div class="container">
<div>
<img src="http://via.placeholder.com/300x150">
</div>
<input type="text">
</div>
<div class="container">
<div>
<img src="http://via.placeholder.com/250x150">
</div>
<input type="text">
</div>