Apu
April 25, 2023 ›
#dynamically
›
#HowTo
❌
How to display textbox value in table using javascript
To display the value of a textbox in a table using JavaScript, you can follow the following steps.
- Get the value of the textbox using its id attribute.
- Get a reference to the table and its tbody element, where you want to display the value.
- Create a new table row (tr element) and two table cells (td elements) to display the value.
- Set the text content of the first cell to a label for the value.
- Set the text content of the second cell to the value itself, which we got from the textbox.
- Add the new row to the table's tbody element.
<input type="text" id="my-textarea" placeholder="Type Your Name">
<table id="my-table" border="">
<tbody></tbody>
</table>
<button onclick="myFunction()">Submit</button>
<script>
function myFunction(){
let textboxValue = document.getElementById("my-textarea").value;
let table = document.getElementById("my-table");
let tbody = table.getElementsByTagName("tbody")[0];
let newRow = tbody.insertRow();
let cell1 = newRow.insertCell(0);
let cell2 = newRow.insertCell(1);
cell1.textContent = "Textbox value:";
cell2.textContent = textboxValue;
}
</script>
This example adds a new row to the table's tbody element and sets the text content of the two cells to display a label "Textbox value:" and the value of the textbox, respectively.
save
listen
AI Answer
How to display textbox value in table using javascript
0
To display the value of a textbox in a table using JavaScript, you can follow the followi…
asked
Apu
0 answers
2915
To display the value of a textbox in a table using JavaScript, you can follow the followi…
Answer Link
answered
Apu
