473,221 Members | 1,820 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,221 software developers and data experts.

[Web] Focus on first visible control

I have a Web form with a number of text boxes. If the user submits the
page with some text boxes filled in, those then become plain text
(with accompanying <input type="hidden"> fields for when the page is
resubmitted) - so the number of text boxes varies.

I was using this to focus on the first text box:

<body onLoad="document.forms[0].elements[0].focus();">

But it doesn't work when the first text box has been removed. In
effect, the browser is setting the focus to the new first control
(with type="hidden") so the caret is not visible.

How can I focus on the first *visible* input element?

P.
Jul 23 '05 #1
5 3324
you can test if the controle/element is of type == "text".

Jul 23 '05 #2
Lee
Paul E Collins said:

I have a Web form with a number of text boxes. If the user submits the
page with some text boxes filled in, those then become plain text
(with accompanying <input type="hidden"> fields for when the page is
resubmitted) - so the number of text boxes varies.

I was using this to focus on the first text box:

<body onLoad="document.forms[0].elements[0].focus();">

But it doesn't work when the first text box has been removed. In
effect, the browser is setting the focus to the new first control
(with type="hidden") so the caret is not visible.

How can I focus on the first *visible* input element?


Whatever server-side code you're using to create the hidden fields "knows" which
is the first visible field. Have it modify the onload handler accordingly.

Jul 23 '05 #3
Oh, I've found a solution myself.

I'm using the 'type' property to check that an input is 'text' (and
not, say, 'hidden').

function focusFirstVisibleInput()
{
var d = document.forms[0];
for (var i = 1; i <= d.elements.length; i++)
{
var e = d.elements['a' + i];
if (e.type == 'text')
{
e.focus();
break;
}
}
}

P.
Jul 23 '05 #4
Paul E Collins wrote:
Oh, I've found a solution myself.

I'm using the 'type' property to check that an input is 'text' (and
not, say, 'hidden').

function focusFirstVisibleInput()
{
var d = document.forms[0]; for (var i = 1; i <= d.elements.length; i++)


I would start from 0(zero).
Mick

Jul 23 '05 #5
Lee
Mick White said:

Paul E Collins wrote:
Oh, I've found a solution myself.

I'm using the 'type' property to check that an input is 'text' (and
not, say, 'hidden').

function focusFirstVisibleInput()
{
var d = document.forms[0];

for (var i = 1; i <= d.elements.length; i++)


I would start from 0(zero).


and end at the last element, even though you should
never actually get past it in this application:

for (var i = 0; i < d.elements.length; i++)

Jul 23 '05 #6

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

Similar topics

5
by: Melissa | last post by:
1. Is there a way to programatically remove the focus from the form; ie, so the focus is not on any control on the form? 2. Is there a way to programatically set the focus to the same place as...
2
by: James | last post by:
Hi I have set up a subform in datasheet mode containing a second subform also in datasheet mode in order to be able to open it as a subdatasheet. In my application I make the first subform...
12
by: Stephen Poley | last post by:
I have a report which prints data from a parent table and two child tables (Contract and Kosten). Because it is a bit long, I suppress some fields which are often empty, based on methods found in...
0
by: Stephen Bedford | last post by:
I am developing an application that is primarily keyboard not mouse driven. Navigation is very difficult within some controls (list boxes, radio groups etc) unless the focus rectangle is visible. ...
4
by: PK9 | last post by:
I have a button at the top of my page that I have an onClick event handler for which makes some new controls (at the bottom of my page) visible. When the user clicks the button I make the new...
5
by: Glenn T. Kitchen | last post by:
Hello All, Does anyone know how to set the focus to a textbox control on Page_Load? Thank you, Glenn
0
by: LCAdeveloper | last post by:
Another newbie question I'm afraid. When I use the .Focus() or .Select() methods to set the initial control that has focus on a form, try as I might I cannot get the control to visually indicate...
1
by: Praveena.Alapati | last post by:
Hi, There is a tab control on a page with multiple tabs and handful of controls in each tab. The way it's rendered in html (like grid etc..) is in table format in tablerows and cells. On...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.