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

143
Views
How to get the values or texts from HTML select tag using JavaScript?

In my html file i have the following:

<td id="trainers_rowC1">Trainer1</td>

<td><input type="button" id="edit_button1" value="Edit" class="edit" onclick="edit_rowC('1')"></td>

In my JavaScript file i have this function:

function edit_rowC(no) {
    var trainers = document.getElementById("trainers_rowC" + no);
    var trainers_data = trainers.innerHTML;
    trainers.innerHTML = "<select id ='trainers_options" + no + "'><option value='" + trainers_data + "'>";
}

But when i press the Edit button the dropdown menu is empty. What is the mistake?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This works for me.

Your mistake was that you tried to set the content of the option tag with value="...". But you have to write it between the two tags. --> <option>" + test + "</option>

function edit_rowC(no) {
    var test = document.getElementById("trainers_rowC" + no).innerHTML;
    document.getElementById("trainers_rowC" + no).innerHTML = "<td><select id ='trainers_options" + no + "'><option>" + test + "</option><option>test</option></select></td>";
}

about 4 years ago · Juan Pablo Isaza Report

0

There doesn't seem to be any closing tags in the assignment of trainers.innerHTML - could that be it?

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!