JavaScript – Focus function

Focus will keep object to ready for work. If you loose focus from object you cannot do work on that object. We can work on only active object. To activate object we need focus on that. JavaScript focus function solves our problem. Focus on text field keeps the cursor inside text field and we can start writing in the field.

If we want to select text and copy text, focus should be on that window. Window can be focused by focus function.

Focus function helps to focus on almost all input field (Select, password, radio button, checkbox) and user does not need to use mouse. Only keyword will do all input and submit the form.

document.formName.fieldName.focus();

 

window.focus();

Full example

<html>
<head>
<title>Javascript focus</title>
<script>
function getFocus()
{
 document.frm.fieldName.focus();
}
</script>
</head>

<body>
<form name="frm">

 <input type="text" name="fieldName" />

</form>

<script>getFocus()</script>

</body>
</html>
Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post