473,574 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form focus

GTi
Is it possible to have a generic script that set the input focus on the
first valid element in a document (not hidden or disabled) ?

This script is at the end of a document, but don't work.

<script type="text/javascript">
document.forms[0].elements[0].focus();
</script>

Jan 19 '06 #1
4 4183
GTi wrote on 19 jan 2006 in comp.lang.javas cript:
Is it possible to have a generic script that set the input focus on the
first valid element in a document (not hidden or disabled) ?

This script is at the end of a document, but don't work.

<script type="text/javascript">
document.forms[0].elements[0].focus();
</script>
Perhaps the DOM is notyet finished being build.
Use body onload='' or a setTimer().
(not hidden or disabled)


It is your document, so why make a long script for this?

Try:

<body onload='documen t.getElementByI d("firstOne").f ocus()'>
.....
<input id='firstOne'>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 19 '06 #2
GTi
Evertjan. wrote:
GTi wrote on 19 jan 2006 in comp.lang.javas cript:
Is it possible to have a generic script that set the input focus on the
first valid element in a document (not hidden or disabled) ?

This script is at the end of a document, but don't work.

<script type="text/javascript">
document.forms[0].elements[0].focus();
</script>


Perhaps the DOM is notyet finished being build.
Use body onload='' or a setTimer().
(not hidden or disabled)


It is your document, so why make a long script for this?

Try:

<body onload='documen t.getElementByI d("firstOne").f ocus()'>
....
<input id='firstOne'>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Evertjan,

To make a long story short:
I don't have full access to the whole document from my ASP.NET code.

Explanation:
I use plug in technology and my html code is placed in a placeholder on
a master plug in page. The main page don't know about the form element
names in the document. And the plug in page don't have access to the
main body.

However I did find this script:
if(document.for ms.length > 0)
{
var field = document.forms[0];
for (i = 0; i < field.length; i++)
{
if ((field.element s[i].type == "text")
|| (field.elements[i].type == "textarea")
|| (field.elements[i].type.toString( ).charAt(0) == "s")
{
document.forms[0].elements[i].focus();
break;
}
}
}
But it don't put the focus on any select items.
I think field.elements[i].type.toString( ).charAt(0) == "s"
is trying to solve it, but it dont.

Jan 19 '06 #3
GTi wrote on 19 jan 2006 in comp.lang.javas cript:
To make a long story short:
I don't have full access to the whole document from my ASP.NET code.
I would not find that acceptable ;-)
Explanation:
I use plug in technology and my html code is placed in a placeholder on
a master plug in page. The main page don't know about the form element
names in the document. And the plug in page don't have access to the
main body.

However I did find this script:
if(document.for ms.length > 0)
{
var field = document.forms[0];
for (i = 0; i < field.length; i++)
{
if ((field.element s[i].type == "text")
|| (field.elements[i].type == "textarea")
|| (field.elements[i].type.toString( ).charAt(0) == "s")
You need an extra ) here.

Now it works
{
document.forms[0].elements[i].focus();
break;
}
}
}
But it don't put the focus on any select items.
I think field.elements[i].type.toString( ).charAt(0) == "s"
is trying to solve it, but it dont.


try:

<form>
<input type='submit'>
</form>

<form>
<input>
</form>
<script type="text/JavaScript">

for (var f =0; f < document.forms. length;f++) {
var field = document.forms[f];
for (var i = 0; i < field.length; i++) {
e = field.elements[i]
if ((e.type == "text")
|| (e.type == "textarea")
|| (e.type.toStrin g().charAt(0) == "s")) {
e.focus();
break;

}
}
}

</script>

The == 's' does not seem to work


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 19 '06 #4
GTi
Evertjan. wrote:
GTi wrote on 19 jan 2006 in comp.lang.javas cript:
To make a long story short:
I don't have full access to the whole document from my ASP.NET code.
I would not find that acceptable ;-)
Explanation:
I use plug in technology and my html code is placed in a placeholder on
a master plug in page. The main page don't know about the form element
names in the document. And the plug in page don't have access to the
main body.

However I did find this script:
if(document.for ms.length > 0)
{
var field = document.forms[0];
for (i = 0; i < field.length; i++)
{
if ((field.element s[i].type == "text")
|| (field.elements[i].type == "textarea")
|| (field.elements[i].type.toString( ).charAt(0) == "s")


You need an extra ) here.

I Know.... copy paste problem.

Now it works
{
document.forms[0].elements[i].focus();
break;
}
}
}
But it don't put the focus on any select items.
I think field.elements[i].type.toString( ).charAt(0) == "s"
is trying to solve it, but it dont.

try:

<form>
<input type='submit'>
</form>

<form>
<input>
</form>
<script type="text/JavaScript">

for (var f =0; f < document.forms. length;f++) {
var field = document.forms[f];
for (var i = 0; i < field.length; i++) {
e = field.elements[i]
if ((e.type == "text")
|| (e.type == "textarea")
|| (e.type.toStrin g().charAt(0) == "s")) {
e.focus();
break;

}
}
}

</script>

The == 's' does not seem to work

I know ;)


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Anyway - I don't think this is a big problem for now since most users
use the mouse on combo boxes.

Jan 19 '06 #5

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

Similar topics

2
3739
by: JJ | last post by:
Hi All, When someone selects a value in a select on a form I want to show the same form with another select with certain values depending on first select. How can I do this? Should I keep acouple of arrays loaded with the second selects values not to be shown till selected in first or what other means? Also how do you reload the current...
7
4878
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes because then it didn't work in IE. How can I enable this javascipt form validation to work in Netscape? When I use netscape, none of the alert boxes...
15
4649
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field...
13
7464
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the...
17
3843
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the...
6
5832
by: Ekim | last post by:
hy, I've got a quite simple application: one windows form that consists of a button, and as soon as the user hits the button a second form shall appear. The difficult thing about it is that I want the new form to be created as "deactivated" - that means that the second form has an editbox in it, and this must NOT have the focus - instead,...
2
5394
by: Sid Price | last post by:
Is there a way of stopping a form getting focus in VB.NET. The scenario I have is a main form and a form used for display only. There are no user controls on the display form and it does not ever need to have the focus. When the displays on the form are updated it appears to get the focus. I would like to prevent this because if the user...
6
2603
by: =?Utf-8?B?U2NvdHQgTGFt?= | last post by:
Hi, I have a VB.NET form with a bunch of controls in it . The focus is in one of the controls , (i.e. a textbox), is there any way to click on the form itself and make the textbox lose focus and have the form gain the focus , so that no control on the form has the focus ? Thanks, Hang
2
2177
by: SONIQ | last post by:
Using javascripts to validate this form. Basic operation, when a user clicks the submit order button, the javascript code must validate everything entered by the user. Please help finnish this form. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
2
7172
by: Joergen Bech | last post by:
Hope someone has a solution or some suggestions for this. This cannot be right?!? Problem: I have multiple non-modal forms open at the same time. One or more of these forms have a ToolStrip, each of which has one or more ToolStripButtons.
0
7794
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8040
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. ...
0
8225
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...
1
7800
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...
0
6437
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5610
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...
0
5296
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...
0
3738
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...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.