Setfocus to textbox from JavaScript after just creating the textbox with JavaScript?
Posted
by Scott
on Stack Overflow
See other posts from Stack Overflow
or by Scott
Published on 2009-03-13T00:09:31Z
Indexed on
2010/04/07
18:23 UTC
Read the original article
Hit count: 266
JavaScript
|focus
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?
© Stack Overflow or respective owner