PDA

View Full Version : Auto focusing Inputs Fields, Sound complicated? It isn't!



DaveMania
April 30th, 2005, 12:37 PM
Basically I'm wondering how i can get an input field to be focused when the page loads. Like when you go to google the "search" field is focused and has the flashing pointer in it.

How do they do it?

Enigmatic
April 30th, 2005, 01:28 PM
<html>
<head>
<script type="text/javascript">

var formInUse = false;

function setFocus()
{
if(!formInUse) {
document.theForm.text1.focus();
}
}

</script>
</head>

<body onload="setFocus()">
<form name="theForm">
<input type="text" name="text1" onfocus="formInUse = true;">
<input type="text" name="text2" onfocus="formInUse = true;">
<input type="text" name="text3" onfocus="formInUse = true;">
</form>
<img src="images/hugePicture.jpg" alt="huge image to slow down
the loading process!">
</body>
</html>

DaveMania
May 1st, 2005, 05:43 AM
thanks, man. And i actually understand it this time!