Upload an image by HTML URL - JS

0

Good morning I'm doing a form in HTML with JS and I have a field to enter an image by URL my idea is to enter with an input type

{ input type="url" placeholder="Enter URL of the image" > }

My question is how can I show the image

    
asked by Enmanuel Ruiz Sepúlveda 01.10.2017 в 07:10
source

1 answer

1

To show the image you should only capture the value entered in your input once it has been changed, that is achieved with the event change , then you must assign that value to src of a label img , something like this:

$("#url").change(function(){
   var url = $(this).val();    
   $("#imagen").html('<img src="'+ url +'" alt="imagen">')
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="url" placeholder="Ingrese URL de la imagen" id="url">
    <div id="imagen"></div>

I hope you serve, greetings!

    
answered by 01.10.2017 в 19:10