How to load an image into an input type img by getting the url of another input

1

Good evening.

I have a form that has an input that receives a url by ajax.

How can I get this url and fill in another input to view the image?

JS ( here the id of the input that will receive the url ):

$("#thumb").val(json.items[0].volumeInfo.imageLinks.thumbnail);

INPUT 1 ( here the input is filled with the url that I will save ):

<input type="text" id="thumb" value="http://books.google.com/books/content?id=-2DSc30QWpEC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api"  />                                              

INPUT 2 ( Here I would like to show the image and I can not ):

<input type="image" src="" id="thumb2" >    

Is it possible?

    
asked by anonymous 10.01.2018 / 03:33

1 answer

1

You have to insert the image into src of input #thumb2 taking value from input #thumb , after Ajax returns at :success :

<script>
...ajax
success: function() {
    $("#thumb2").attr("src",$("#thumb").val());
}
</script>

Inputs of type image must have a src of where they will pull an image, which will be the content of the element.

More information on this MDN documentation .

    
10.01.2018 / 03:44