Forum Moderators: open
<script type="text/javascript">
window.onload = function init() {
if (document.login.Email.value == '') {
document.login.Email.focus();
} else {
document.login.Password.focus();
}
}
</script> <table>
<tr>
<td>Email Address:</td>
<td><input name="Email" size="25" type="text"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="Password" size="25" type="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Login"></td>
</tr>
</table>
DRIVE-BY WARNING: I just happened to be driving by and saw your post. I am NOT an expert or even a novice in JS. But, I can understand some of what I'm looking at and my Cut and Paste routines are second to none. :)
.....
if (document.getElementById('Email')) {
document.getElementById('Email').focus();
} .....
....<input name="Email" id="Email" size="25" type="text">......
Supplement two: be sure this is doing what your users want and not what you think they want, it's #1 on my top ten list [webmasterworld.com]. :-)
The reason being, onload often doesn't execute until the entire page loads. The fields may load before it executes and they may already be in the password field . . . then focus switches to the Email field and an continues to input the password into the email field. Maddening.