473,545 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Focus()

When I validate a form on submission I use the javascript focus function to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location of
the error field and then either add half a windows worth of pixels to it if
it is at the top of the screen or subtract half a windows worth of pixels to
it if it is at the bottom of the screen?

Thanks!
Sep 13 '05 #1
3 6071
Simon Wigzell <si**********@s haw.ca> wrote in message news:eACVe.4788 92$5V4.305000@p d7tw3no...
When I validate a form on submission I use the javascript focus function to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location of
the error field and then either add half a windows worth of pixels to it if
it is at the top of the screen or subtract half a windows worth of pixels to
it if it is at the bottom of the screen?

Thanks!

You could place one or more anchors at strategic points above the relevant fields:

<A name='fieldPoin t'> </A>

then send the page there on error:

document.locati on='#fieldPoint ';

--
S.C.

S.C.

Sep 13 '05 #2

"Stephen Chalmers" <ig******@lycos .co.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
Simon Wigzell <si**********@s haw.ca> wrote in message
news:eACVe.4788 92$5V4.305000@p d7tw3no...
When I validate a form on submission I use the javascript focus function
to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of
the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get
the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location
of
the error field and then either add half a windows worth of pixels to it
if
it is at the top of the screen or subtract half a windows worth of pixels
to
it if it is at the bottom of the screen?

Thanks!

You could place one or more anchors at strategic points above the relevant
fields:

<A name='fieldPoin t'> </A>

then send the page there on error:

document.locati on='#fieldPoint ';

--
S.C.

S.C.

Thanks, that syntax is new to me, that will do it.
Sep 14 '05 #3
Stephen Chalmers wrote:
Simon Wigzell <si**********@s haw.ca> wrote in message news:eACVe.4788 92$5V4.305000@p d7tw3no...
When I validate a form on submission I use the javascript focus function to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location of
the error field and then either add half a windows worth of pixels to it if
it is at the top of the screen or subtract half a windows worth of pixels to
it if it is at the bottom of the screen?

Thanks!


You could place one or more anchors at strategic points above the relevant fields:

<A name='fieldPoin t'> </A>

then send the page there on error:

document.locati on='#fieldPoint ';


Anchors can be created using element ids, A elements aren't required.

It may be useful to use the id of the form as an anchor or the id of
some fieldset inside the form.

<form id="formA" ...>
<!-- controls for for formA -->
</form>

<a href="#formA">S croll to formA</a>


[...]

--
Rob
Sep 14 '05 #4

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

Similar topics

4
2207
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for time and there is also a check on that. If time is empty return error message. Again the explorer returns error message and then shifts the focus...
2
3081
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a Mozilla-only problem) I'm capturing the focus and blur events for the document, updating a
3
6877
by: VA | last post by:
t=document.getElementById('mytable') is a HTML table with some input fields in its cells Why doesnt t.getElementsByTagName('tr').firstChild.focus; put the focus on that text field? It doesnt give any errors, the focus just doesnt change.
17
3837
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...
1
2226
by: avnrao | last post by:
Hi, I am facing a problem with control.focus (javascript). Here is the description of the issue. 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on this, will redirect page to Aspx2 which has a Datagrid. PageLoad of Aspx2 displays the DataGrid with existing data filled in and shows a new row (set of text boxes) in...
4
3933
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several textboxes and a checkbox. The behaviour I want from my app is as follows:- When the textbox (which is prior in tab order to the tab control) has...
11
7320
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz 1.7.12 (linux kubuntu). It does work with konqueror. It seems to work with firefox on windows but not with IE (not completly sure though).
7
11906
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click' and it steals the focus from the user's current application. How can I prevent the hidden WebBrowser from stealing focus? (And better yet can I...
4
67973
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between these forms that may make one succeed and another fail? In particular, this.window.focus() fails in Opera 9.10 with an "object not found", and...
3
5182
by: jp2express | last post by:
I have several applications that use panels as screens, but I can *not* seem to set the focus for a Textbox. Panel1.BringToFront() Panel1_Textbox.Focus() ' do something with a control on Panel1 Panel2.BringToFront() Panel2_Textbox.Focus() ' do something with a control on Panel2
0
7487
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
7934
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
7446
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
6003
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
5349
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
4966
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
3476
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...
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.