Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
in html ? how to make auto focus input
Posted

HTML
<input type="text" id="txt" />

<script type="text/javascript">
$(document).ready(function() {
    $("#txt").click();
});
</script>

This will focus your textbox on page load.

EDIT : As an alternative to solution #2 (which is better), you can refer this solution.

-KR
 
Share this answer
 
v2
In supported browsers, the autofocus attribute[^] is what you're looking for:
HTML
<input type="text" autofocus />

Browser support[^] is pretty good - even IE10+ supports it.
 
Share this answer
 
Comments
Krunal Rohit 21-Oct-15 9:35am    
I like your solution better. :D
Forget to mention autofocus in my answer :doh:

5!
-KR
BilalTy 9-Nov-15 8:19am    
thanks
BilalTy 9-Nov-15 8:20am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900