David
|
| Posted: 04/19/2002, 9:04 AM |
|
Hi Im using this snippet of code to put focus on a form called Login on my
page :
<script language="JavaScript">
document.forms[0].Login.focus();
</script>
But there are conditions when the form isnt displyed mainly when the user is
already logged in, although the page still loads an error is generated in IE
and I was wondering what is the best way for it to only perform a focus if
the form is visible, cheers David
|
|
|
 |
Erik Slooff
|
| Posted: 04/19/2002, 11:08 PM |
|
Hi David,
Have a try with this script which I borrowed. Haven't tried it with a hidden
form but it does more error checking such as checking the field type. Please
reply with your results.
Place in <head>:
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Tom Khoury (twaks@yahoo.com) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function placeFocus() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements.type == "text") || (field.elements.type ==
"textarea") || (field.element.type.toString().charAt(0) == "s")) {
document.forms[0].elements.focus();
break;
}
}
}
}
// End -->
</script>
And place this in footer of the page:
<BODY OnLoad="placeFocus()">
Hope this helps,
Erik
"David" <dava133@ntlworld.com> wrote in message
news:a9pf6e$2gf$1@news.codecharge.com...
> Hi Im using this snippet of code to put focus on a form called Login on my
> page :
>
> <script language="JavaScript">
> document.forms[0].Login.focus();
> </script>
>
> But there are conditions when the form isnt displyed mainly when the user
is
> already logged in, although the page still loads an error is generated in
IE
> and I was wondering what is the best way for it to only perform a focus if
> the form is visible, cheers David
>
>
|
|
|
 |
|