Setfocus to textbox from JavaScript after just creating the textbox with JavaScript?
- by Scott
So I just created a textbox with JavaScript like this:
EDIT: Added the len variable
var len = tbl.rows.length;
var rtb = tbl.insertRow(len);
var cName = rtb.insertCell(0);
var cDis = rtb.insertCell(1);
var cDur = rtb.insertCell(2);
cName.innerHTML = '<input type="text" name="tbName1' + len + '" value="' + selected_text + '" >';
cDis.innerHTML = '<input type="text" name="tbDis1' + len + '" id="tbDis1' + len + '" >';
cDur.innerHTML = '<input type="text" name="tbDur1' + len + '" >';
var txtBox = document.getElementById('tbDist1' + len);
txtBox.focus();
EDIT:Changed the second to last line. Still get this error: txtBox is null
txtBox.focus();
The last line isn't working. After I create the textbox, I can't set focus to it. Is there any way of doing so?