How to set cursor to input box in Javascript?

dom-events, javascript

Solution

In JavaScript first focus on the control and then select the control to display the cursor on texbox...

document.getElementById(frmObj.id).focus();
document.getElementById(frmObj.id).select();

or by using jQuery

$("#textboxID").focus();

Problem

``` document.getElementById(frmObj.id).value=""; document.getElementById(frmObj.id).autofocus; document.getElementById("errorMsg").innerHTML = "Only numeric value is allowed"; ``` In the above code the value of the form object is perfectly setting to `""` but there is no cursor in the text box. I want a cursor to be there. `focus()` only focuses that input box but does not actually set the cursor.

Original source

Related problems