473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting focus to a text box on page load

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?
Mar 28 '06 #1
3 2479
After sending the previous message, I changed

strScript = strScript & "document.forms[0].txtUserName.focus();"

to

strScript = strScript & "document.getElementById('txtUserName').focus( )"

and the error message went away. Still, something has changed on the
servers to cause the error in the first place.

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
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?

Mar 28 '06 #2
Replace

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

with

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

Eliyahu

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
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?

Mar 28 '06 #3
Thanks. I did that, and everything is now fine.

But why did the other code work for over a year before throwing the error
only recently?
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
Replace

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

with

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

Eliyahu

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
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?


Mar 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It...
3
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There...
4
by: Wayne Wengert | last post by:
How can I have the focus on a specific textbox when a page opens? In the old ASP pages I could use an onload directive in the <Body> element but that does not work on my aspx pages? Wayne
12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
2
by: parm | last post by:
How do I highlight text in my first (tabindex = 1) asp control (eg: textbox) on the webform on page load. If I try to set focus using javascript then I get script error "Cannot move focus to...
18
by: Charles May | last post by:
I know I've done this somewhere but I cannot find any example of it in any of my test code. I have a form with a Listbox that is filled by a dataset it fills in various textboxes. When the...
3
by: boldt.lars | last post by:
This code works fine in Firefox and Opera, I can see that it put focus on the correct input in IE, but by the time the page has loaded completely it loses focus. The first time you enter the...
8
by: Brad Isaacs | last post by:
Good morning friends, I am working with Visual Studio 2005, ASP.NET 2.0 I am working with the Login controls provided my .NET 2.0, trying to make the Login1 control UserName textbox obtain...
3
by: bananna | last post by:
Hello, In my site I have a link and you click on it, it runs a javascript function where it gets makes a div visable. This is so people can click the link and get a defintion of a word. Here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.