473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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="documen t.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 3344
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="documen t.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 focusFirstVisib leInput()
{
var d = document.forms[0];
for (var i = 1; i <= d.elements.leng th; 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 focusFirstVisib leInput()
{
var d = document.forms[0]; for (var i = 1; i <= d.elements.leng th; 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 focusFirstVisib leInput()
{
var d = document.forms[0];

for (var i = 1; i <= d.elements.leng th; 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.leng th; i++)

Jul 23 '05 #6

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

Similar topics

5
3779
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 is done when the form opens; ie, the first control in the taborder which is visible, which is enabled and whose tabstop property is True? I have a form with forty two small subforms and I want to code the Enter event of all the subform controls...
2
4480
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 appear and disappear using the Visible property. If I make it visible (in code), open the subdatasheet (via mouse) and click anywhere on the subdatasheet, then make it invisible (in code) I get the infamous error 2165 'You can't
12
2059
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 the archive for this group: allowing can-shrink on the field itself and the following code in the details section to suppress the label: If (Me!InpassingWerkproces.Text = "") Then Me!InpassingWerkproces_Bijschrift.Visible = False Else...
0
2145
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. When an application starts the focus rectangle for a control is never visible and only becomes visible once the TAB key is pressed. After that everything works OK. In a list box I have looked at the ChangeUICues event of the control and there is a...
4
3133
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 controls visible in the onclick event handler, but I do not know how to bring the focus to the bottom section of the page. So basically, when the user clicks the button, everything works correctly in the onclick (all controls are made visible),...
5
1359
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
1543
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 that it has the focus (e.g. a dotted outline around the caption of a RadioButton). The visible and enabled properties are set to true, and I know that the desired control has the focus (in this case one of two or more RadioButtons located in a...
1
2510
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 clientside, on form validation in javascript, I would like to set focus on to one of the tabs and set the focus to the control on that tab.
3
7505
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 on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.