JavaScript : Form focus on load
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com Created by: Lee Underwood | http://javascript.internet.com/ */ function getFocus() { // place the id below of the field you want to have focus upon page load var focusHere = document.getElementById("yourName"); focusHere = focusHere.focus(); } // Multiple onload function created by: Simon Willison // http://simonwillison.net/2004/May/26/addLoadEvent/ function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(function() { getFocus(); }); |
Written by Komkid on August 5th, 2009 with
no comments.
Read more articles on JavaScript and Programming.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article