As an answer to the question of \'How do you automatically set the focus to a textbox when a web page loads?\', Espo suggests using
I can see no other reason than the possible later override, which would lead to your code never being executed. Also, obtrusive javascript is not in very high regard anymore.
You should instead assign a function listening to the event. You can do it like this:
function onloadFocus() {
document.getElementById('<id>').focus();
}
if (window.addEventListener) {
window.addEventListener('load', function(e) {onloadFocus();}, false);}
else if (window.attachEvent) {
window.attachEvent('onload', function(e) {onloadFocus();});
}
...or rely on a javascript framework, such as jquery, that would provide the same functionality for you.
Another way to look at it is using an addEventListener
instead of using it as an html code try JS:
<body onLoad="document.getElementById('<id>').focus();">
<body>
<script>
document.body.addEventListener('load', funcLoad);
function funcLoad(){
document.getElementById('<id>').focus();
}
</script>
</body>
Try it out, it might work better than other solutions.