Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!