Re: Setting focus to a text box on page load

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Replace

document.forms[0].txtUserName.focus();

with

document.getElementById("txtUserName").focus();

Eliyahu

"William LaMartin" <lamartin@xxxxxxxxxxxxxxx> wrote in message
news:%23H2u99gUGHA.776@xxxxxxxxxxxxxxxxxxxxxxx
All of a sudden code that had been working at my websites to set the focus
to a particular text box on page load now produces an error.

The code is:

'put the focus on the first text box
Dim strScript As String
strScript = "<script>"
strScript = strScript & "document.forms[0].txtUserName.focus();"
strScript = strScript & "</script>"
Page.RegisterStartupScript("ClientScript", strScript)

And the error produced is: 'document.forms.0.txtUserName' is null or not
an
object

It is happening in my development computer as well at sites. All I can
figure is that some Windows update changed IIS in some way.

What is the solution?




.