Forum Moderators: open
I want to be able to write the value of what the user inserts in a text box to a table cell.. I know it sounds wierd but there is a bigger picture here.
At the moment all i can do is write what the user inserts into another textbox..
Here is my function. (where TheText is the original text and Text2 is the duplicated text)
function duplicateText()
{
document.TheForm.Text2.value = document.TheForm.TheText.value;
}
<body onkeyup="duplicateText();">
This copys what the user write from one box to another.
How do i copy this text to a table cell?
Do i use the getElementByID function.
Any help greatly appreciated.
Ally
You're definitely on the right track. First you'll want to assign an id to the table cell that you want to change. Then on the input field, you can do something like this:
<input type="text" onkeyup="document.getElementById('test').innerHTML=this.value;">
Replace "test" with whatever id you gave your table cell, and it should update it on the fly. Note that this is case-sensitive, and "innerHTML" doesn't follow normal javascript capitlization.
Chad
Are you still with me ;)
var allTDs = document.getElementsByTagName('td'); allTDs is now an array containing all the TDs in the document. As with all arrays, you can loop through it or address individual items, e.g. allTDs[5].