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();"> Link to comment https://forums.phpfreaks.com/topic/102302-doubt-regarding-setfocus/ 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... Link to comment https://forums.phpfreaks.com/topic/102302-doubt-regarding-setfocus/#findComment-523815 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... Link to comment https://forums.phpfreaks.com/topic/102302-doubt-regarding-setfocus/#findComment-523844 Share on other sites More sharing options...
smiley_kool Posted April 22, 2008 Author Share Posted April 22, 2008 thank u.. Link to comment https://forums.phpfreaks.com/topic/102302-doubt-regarding-setfocus/#findComment-523845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.