Set focus on a text box

J

JCO

Does anyone know how to ensure a textbox has the focus set (when the page is
open)?
Thanks
 
C

Chet

| Does anyone know how to ensure a textbox has the focus set
(when the page is
| open)?
| Thanks
|
Try either of these:

1) place the onload handler below into the page's body tag:

onload="document.formname.fieldname.focus();"

2) if you already have an onload handler in the body tag, you can
use the below javascript, place it just after the body tag:

<script>
document.formname.fieldname.focus();
</script>

In either, you'll have to change the "formname" to your form's
name and "fieldname" to the field you want focus on.

hth
 
J

Jon

Just as a note to this
2) if you already have an onload handler in the body tag, you can
use the below javascript, place it just after the body tag:

<script>
document.formname.fieldname.focus();
</script>

You would need to place this after the form element you want to focus - not
just after the body tag. If you try and address a form element with
javascript before the form element appears in the page you'll get an error,
eg
Bad
<script>
document.formname.fieldname.focus();
</script>
<form>
....your form fields
</form>
Good
<form>
....your form fields
</form>
<script>
document.formname.fieldname.focus();
</script>



Jon
Microsoft MVP - FP
 
C

Chet

| Just as a note to this
| > 2) if you already have an onload handler in the body tag, you
can
| > use the below javascript, place it just after the body tag:
| >
| > <script>
| > document.formname.fieldname.focus();
| > </script>
|
| You would need to place this after the form element you want to
focus - not
| just after the body tag. If you try and address a form element
with
| javascript before the form element appears in the page you'll
get an error,
| eg
| Bad
| <script>
| document.formname.fieldname.focus();
| </script>
| <form>
| ...your form fields
| </form>
| Good
| <form>
| ...your form fields
| </form>
| <script>
| document.formname.fieldname.focus();
| </script>
|
|
|
| Jon
| Microsoft MVP - FP

Thanks Jon, I appreciate the info. I'd gotten these two quite
some time ago and had only use the onload handler so I wasn't
aware of having to place the script after the form.

Regards,
 
J

JCO

I took your advise and moved the "onload" to the bottom of the form.
Therefore the form is loaded before the onload is call (that sets the focus
to the textbox).

Now the focus is set, however, the cursor is blinking. It seems to have
some interference with existing animation that is going on in the
TopFrameSet and LeftFrameSet.. I'm just guessing about the interference
with the existing animation, but the cursor is blinking and is a disturbance
for the user to type the password.

Any ideas on this?
 
Top