here's how you set the focus in the first input text textfield of an html page when the page loads.
put this in your page template header (inside the <head> tag, or just inside an individual page's <head> tag):
<script type="text/javascript" src="/scripts/keyboard-controls.js"></script>
create a file here:
scripts/keyboard-controls.js
scripts/keyboard-controls.js
function setFocusOnFirstTextfield() {
var nodeList = document.getElementsByTagName("input");
for(item in nodeList) {
if(nodeList[item].getAttribute("type") == "text" || nodeList[item].getAttribute("type") == "password") {
nodeList[item].focus();
break;
}
};
}
put this in your page template footer (or just at the bottom of an individual html page):
<script type="text/javascript">
setFocusOnFirstTextfield();
</script>
(right before the closing body tag, </body>)
so, if you're using a template for your header and footer, then this code will work for all pages in your project :)
IT, computer and programming tutorials and tips that i couldnt find anywhere else using google, from my daily work as a Senior Developer of solutions using Java and Linux.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment