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

98
Visualizações
Button that adds the selected value to a textarea

I want to create a list of "Select" photos that by choosing one I can press a button and add some code to a textarea along with the chosen value.

I wrote this html code with external "JS" file but not being familiar with javascript I don't understand where I'm wrong. I looked around a bit but I only found examples with jquery and that operate on on.change, while I need the value to be entered when the button is pressed plus must add the additional text along with the choice.

I would like to avoid using JQuery for a matter that this code has to run locally without being updated.

function Art_AddFoto() {
  var Fotoselect = document.getElementById('art_fotoselect');
  var Selectvalue = Fotoselect.options[select.selectedIndex].value;

  var TextArea = document.getElementById('i251x');
  TextArea.innerText += '<img src="' + Selectvalue + "' alt='Image'>";
});
<textarea class="textarea" style="height:200px;" name="art_testo" id="i251x"> </textarea>

<select class="select" name="art_fotoselect" id="art_fotoselect">
  <option value="test1">value1</option>
  <option value="test2">value2</option>
</select>

<div style="width:40%; display:inline-block;">

  <input type="button" name="Art_AddFoto" value="Aggiungi Foto" onclick="Art_AddFoto()" class="button">
</div>

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

0

Here can be a good start for you:

It use querySelector and EventListener

Art_AddFoto = (e) => {
document.querySelector('#i251x').value += document.querySelector('#art_fotoselect').value+"\r\n";
}

document.querySelector("#Art_AddFotoBtn").addEventListener('click',()=>{
Art_AddFoto(this)
})
<textarea class="textarea" style="height:200px;" name="art_testo" id="i251x"></textarea>

<select class="select" name="art_fotoselect" id="art_fotoselect">
                <option value="test1">value1</option>
                <option value="test2">value2</option>
</select>

<div style="width:40%; display:inline-block;">

    <button name="Art_AddFoto"class="button" id="Art_AddFotoBtn">Aggiungi Foto</button>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

You are so close!

The only change I had to make to your code was swapping select for Fotoselect:

function Art_AddFoto() {
    var Fotoselect = document.getElementById('art_fotoselect');
    var Selectvalue = Fotoselect.options[Fotoselect.selectedIndex].value;

    var TextArea = document.getElementById('i251x');
    TextArea.innerText += '<img src="' + Selectvalue + "' alt='Image'>";
}    
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