smiley_kool Posted April 22, 2008 Share Posted April 22, 2008 hi.. can someone temme , how to set setfocus on a particular textbox (or form) on pageload.. i tried to give like this i a form ,but its not wrking.. <form name='form_name' action=' ' method='POST' onLoad="document.form_name.name.focus();"> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 22, 2008 Share Posted April 22, 2008 when trying to force the focus onto an element within a page its only useful to do so on one the user can interact with - so some kind of form element (input, textarea etc.) or a link. This should be done in an unobtrusive manner... Give the element you wish to set the focus on an id (remember id's must be unique) like so <input type="text" name="username" id="username" /> in the head section of the page place a script tag to an external js file which contains... window.onload = setInitialFocus; function setInitialFocus () { document.getElementById('username').focus() } Lovely stuff... Quote Link to comment Share on other sites More sharing options...
smiley_kool Posted April 22, 2008 Author Share Posted April 22, 2008 when trying to force the focus onto an element within a page its only useful to do so on one the user can interact with - so some kind of form element (input, textarea etc.) or a link. thank u.. This should be done in an unobtrusive manner... Give the element you wish to set the focus on an id (remember id's must be unique) like so <input type="text" name="username" id="username" /> in the head section of the page place a script tag to an external js file which contains... window.onload = setInitialFocus; function setInitialFocus () { document.getElementById('username').focus() } Lovely stuff... Quote Link to comment Share on other sites More sharing options...
smiley_kool Posted April 22, 2008 Author Share Posted April 22, 2008 thank u.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.