Click here to Skip to main content
15,909,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All ,

I am trying to focus the fourth text box control in javascript but i am not able to get the cursor on fourth textbox,when page loading the cursor goes to the fourth text box position but after fully loading the textbox the cursor not able to focus the that text box,
can any one help me..this. i have write the code like
JavaScript
document.getElementById('custpage_scanitem').focus();

But i didn't get the output..
Posted
Updated 6-Jun-13 2:13am
v2
Comments
Sunasara Imdadhusen 6-Jun-13 8:13am    
you have to write your code after your page getting loaded!
Ganesh_mca 6-Jun-13 8:24am    
when i open the page that will automatically focus that textbox ,i was write the code in Page init event.
Mac12334 6-Jun-13 8:48am    
use AutoFocus attribute of html5

http://www.html5tutorial.info/html5-autofocus.php

1 solution

Why dont you try to load it onLoad() page event,so that it will focus as soon as your page is loaded. The problem now might be that you are trying to call focus method on your element even before it is created hence it not being focused.
JavaScript
function myFocus(){
 document.getElementById('custpage_scanitem').focus();
}


Write the below code in html

HTML
<body onload="myFocus"></body>
 
Share this answer
 

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