I have a JavaScript code that makes sure a text box is selected when my page loads. I have included my code below:
<!doctype html>
<html>
<head>
<script type="text/javascript">
function box(query){
document.getElementById('query').focus();
}
</script>
</head>
<body onload="box('query');">
<input id="query">
</body>
</html>
My question is; How can I make this script work without onload in my body tag?
I hope you can understand what I am trying to describe.
Thanks in advance, Callum
Place it inside the closing
</body>tag, so that thequeryelement has loaded before it runs: