Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Show two different size of image when url is pasted in the textbox

I'm unable to resize the image. Here's my code

document.getElementById('btn1').addEventListener('click', function(){
  document.getElementById('photo').innerHTML = '<img src="'+ document.getElementById('imglink').value +'"?width=400&height=400&fit=crop"/>';
});
<!DOCTYPE html>
<html>
<body>

<form action="#" method="post">
  <input type="url" name="imglink" id="imglink"  placeholder="Insert image URL here" /><br>
  <input type="button" value="Show Image" id="btn1" />
</form>
<div id="photo"></div>

</body>
</html>

What I want is when I pasted the url the image will be displayed on 2 different divs and will resize automatically. However, I need two different size of the image. First div size would be the number1 and the second div is number2. I don't know how to put this size on the javascript code.

  1. ?width=400&height=400&fit=crop
  2. ?width=800&height=450&fit=crop

How can I do that?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can add values for width and height using javascript like this:

'<img src="'+ document.getElementById('imglink').value +'" width="400" height="400" fit="crop"/>'

Try the snippet below:

document.getElementById('btn1').addEventListener('click', function(){
  // Image1
  document.getElementById('image1').innerHTML = '<img src="'+ document.getElementById('imglink').value +'" width="400" height="400" fit="crop"/>';
 // Image2
   document.getElementById('image2').innerHTML = '<img src="'+ document.getElementById('imglink').value +'"width="800" height="450" fit="crop"/>';
  
});
<!DOCTYPE html>
<html>
<body>

<form action="#" method="post">
  <input type="url" name="imglink" id="imglink"  placeholder="Insert image URL here" /><br>
  <input type="button" value="Show Image" id="btn1" />
</form>

<div id="image1"></div>
<div id="image2"></div>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda