473,508 Members | 2,207 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 4177
GTi wrote on 19 jan 2006 in comp.lang.javascript:
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='document.getElementById("firstOne").focus( )'>
.....
<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.javascript:
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='document.getElementById("firstOne").focus( )'>
....
<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.forms.length > 0)
{
var field = document.forms[0];
for (i = 0; i < field.length; i++)
{
if ((field.elements[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.javascript:
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.forms.length > 0)
{
var field = document.forms[0];
for (i = 0; i < field.length; i++)
{
if ((field.elements[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.toString().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.javascript:
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.forms.length > 0)
{
var field = document.forms[0];
for (i = 0; i < field.length; i++)
{
if ((field.elements[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.toString().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
3735
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...
7
4862
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...
15
4643
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...
13
7442
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...
17
3831
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...
6
5822
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...
2
5384
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...
6
2596
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...
2
2171
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...
2
7163
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...
0
7231
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
7336
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,...
0
7401
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...
1
7063
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
5640
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,...
1
5059
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...
0
4720
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...
0
1568
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 ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.