Javatpoint Logo

what is the purpose of focus() in javascript?

By: manasa*** On: Tue May 21 14:50:46 EDT 2013     Question Reputation3 Answer Reputation0 Quiz Belt Series Points0  3Blank User
for example
fomname.uname.focus();
after validating the username field we are writing the above line why??
Up0Down

 
it focus that text field,mean the cursor'll move to text field having the name="uname"Image Created0Down

By: [email protected] On: Wed May 22 02:24:40 EDT 2013 Question Reputation0 Answer Reputation147 Belt Series Points0 147User Image
Are You Satisfied :1Yes1No
 
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.


The focus() method is used to set the focus to a text field.
so you are doing same here
Image Created2Down

By: [email protected] On: Wed May 22 02:39:48 EDT 2013 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :1Yes1No