Sunday, January 24, 2010

Set focus to an html input box and set the cursor to the end of the string


<html>
<head>
<script language="JavaScript">
function setFocus()
{
// Without line 1 and line 2, the cursor will be at the beginning.
value = document.getElementById("input1").value; // line 1
document.getElementById("input1").focus();
document.getElementById("input1").value = value; // line 2
}
</script>
</head>

<body>
<input id="input1">some text</input>
</body>
</html>

No comments:

Post a Comment