473,407 Members | 2,315 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,407 software developers and data experts.

Detecting when the user has gone back a page

We have a little piece of JavaScript in one of our client's application
which automatically sets the input focus to the first control on the HTML
form.

This works very nicely, except for in one circumstance. If the user is
partway through entering data into the form, clicks a hyperlink to go to
another page, and then clicks the Back button to return to the edit page,
the focus is again reset to the first field on the page. Under this
circumstance I would like the focus to be left wherever the user has
previously put it.

Simply put, I want to only set the focus if the user hasn't already set it
during a previous access to this page.

I can do this in IE by querying the document.activeElement.tagName property.
If this returns BODY, then I know that the focus is in its default state and
can set it appropriately. But Firefox doesn't appear to support the
document.activeElement property, so I can't use this mechanism here.

Can anyone suggest a way to do this that will work in Firefox? The ideas I
have which may provide a solution are:

- see if the focus is set to the default location on the page (whatever that
is) -- how would I do this? I'm not sure how to determine what currently has
the focus in Firefox.

- see if there are pages in the history buffer ahead of the current page
(i.e., that would be reached by clicking the Forward button in the
browser) -- how would I do this?

If anyone could answer either of those questions, or suggest another way I
may be able to achieve my goal, I'd be very grateful.

Thanks in advance,

--

(O)enone
Dec 6 '05 #1
1 2781
> "Oenone" <oe****@nowhere.com> wrote:
news:0V******************@newsfe1-win.ntli.net....

We have a little piece of JavaScript in one of our client's
application which automatically sets the input focus to the first
control on the HTML form.

This works very nicely, except for in one circumstance. If the user
is partway through entering data into the form, clicks a hyperlink
to go to another page, and then clicks the Back button to return to
the edit page, the focus is again reset to the first field on the
page. Under this circumstance I would like the focus to be left
wherever the user has previously put it.

Simply put, I want to only set the focus if the user hasn't already
set it during a previous access to this page.

I can do this in IE by querying the document.activeElement.tagName
property. If this returns BODY, then I know that the focus is in
its default state and can set it appropriately. But Firefox doesn't
appear to support the document.activeElement property, so I can't
use this mechanism here.

Can anyone suggest a way to do this that will work in Firefox? The
ideas I have which may provide a solution are:

- see if the focus is set to the default location on the page
(whatever that is) -- how would I do this? I'm not sure how to
determine what currently has the focus in Firefox.

- see if there are pages in the history buffer ahead of the current
page (i.e., that would be reached by clicking the Forward button in
the browser) -- how would I do this?

If anyone could answer either of those questions, or suggest
another way I may be able to achieve my goal, I'd be very grateful.

Thanks in advance,


Use a hidden input to keep track of the elements onfocus.
<input id="tracker" type="hidden" disabled="true">

In each one of your form elements use the onfocus and set tracker value to the id
<input type="text" id="t1" name="address" onfocus="/* set tracker value to this id */">

Your onload can check to see if the hidden tracker element has a value, if it does you can set
focus to that id, if it does not you can set focus to an element of your choice.

--
BootNic Wednesday, December 07, 2005 1:56 AM

A priest, a minister and a rabbi walk into a bar. The bartender says...What is this, a joke?
*Unknown*

Dec 7 '05 #2

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

Similar topics

6
by: Astra | last post by:
Hi All I've noticed on quite a few ASP sites that when they have a 'MyAccount' section they transfer the site to https and then when you have logged into your account successfully and gone back...
2
by: Simon Harvey | last post by:
Hi all, Is there any easy way to check a field for calues that have changed on a post back. So the page is sent to the user, the user changes some values and I need to know which ones...
4
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been...
7
by: Simon Harvey | last post by:
Hi everyone, I'm having a frustrating problem and I don't know how to fix it without totally redoing a very complicated couple of pages on my site. I really hope some kind soul can help me :-) ...
7
by: Markus McGee | last post by:
Hi all, I have a quick question...I believe. On my web page, call it page A, I have a drop downlist with runat server enabled. When the drop downlist change event occurs it repopulates a...
12
by: ACaunter | last post by:
Hi all, I was wondering how i could write some code which would automatically open the Login Page once the session has expired? -- AdamPC@hotmail.com
5
by: Russell | last post by:
Hi all, I have a web page(a) that has a link to another web page(b). Now, on the page load event of web page(b), I am doing the following: Response.redirect("./test.pdf") This pdf, if the...
5
by: needin4mation | last post by:
Hi, I have an asp.net 1.1 application that populates data from a database. When the user changes data, they have to hit a button to update the data. The data entry form (same form that is...
3
by: whapts3 | last post by:
I'm putting together a rather dynamic page (AJAX/all-that-mess). So... to go between different sorts of content on the page, I have it set up something like this. <a href="#10"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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...
0
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...

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.