473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keep form elements enabled on "back" request

Hello everybody,

I have some code that disables form elements on body load, but I notice
when I hit the "back" button, I need to re-enable the form elements
(that is done by clicking on a radial button). Is there any way I can
keep the form for disabling every time a user hits the back button and
"remember" what elements should be enabled? I was thinking maybe
utilizing some referrer thing, but I'm not that good with JS yet.

Thanks for your help!

here is a snip-it from the code:

<script language="JavaS cript">
function Disable_All()
{
document.frmPos t.employeename. className="disa bled";
document.frmPos t.employeename. disabled = true
document.frmPos t.copyfromemplo yee.className=" disabled";
document.frmPos t.copyfromemplo yee.disabled = true
document.frmPos t.effdate.class Name="disabled" ;
document.frmPos t.effdate.disab led = true
document.frmPos t.branch.classN ame="disabled";
document.frmPos t.branch.disabl ed = true
document.frmPos t.jobtitle.clas sName="disabled ";
document.frmPos t.jobtitle.disa bled = true
document.frmPos t.defprinter.cl assName="disabl ed";
document.frmPos t.defprinter.di sabled = true
document.frmPos t.printerdesc.c lassName="disab led";
document.frmPos t.printerdesc.d isabled = true
document.frmPos t.extraservice. className="disa bled";
document.frmPos t.extraservice. disabled = true
document.frmPos t.assistance.cl assName="disabl ed";
document.frmPos t.assistance.di sabled = true
for (var i = 0;i<8;i++){
document.frmPos t.elements.hwre qested[i].disabled = true;
}
for (var i = 0;i<5;i++){
document.frmPos t.elements.swre quested[i].disabled = true;
}
}
</Script>
<body onLoad="Disable _All();">

Jul 23 '05 #1
5 2442
Dani wrote:
I have some code that disables form elements on body load, but I notice
when I hit the "back" button, I need to re-enable the form elements
(that is done by clicking on a radial button). Is there any way I can
keep the form for disabling every time a user hits the back button and
"remember" what elements should be enabled?
No.
I was thinking maybe utilizing some referrer thing,
While the proprietary document.referr er property is seldom of use, it is
certainly not of use here. There is no "back" request as you imply with
the subject. The reknowned Back (button) feature is AFAIS implemented
either accessing the UA's cache or re-sending a GET request to the
previous URI stored in the "window"'s history. This means

1. the document.referr er property, if supported and if it contains a usable
value (which depends on the user agent, of course), will not contain the
"next" URI but the URI of the resource displayed before the form with the
disabled controls, if there was any.

2. because you do not have control over the user agent's cache usage,
you cannot assume any of the described behavior of a Back (button)
feature, if there is any. Especially, onload scripts are not executed
when using that feature and the document is accessed on the local cache.
but I'm not that good with JS yet.
This is not really a JS issue. Either don't disable the controls on load
(which would be best, considering that there are UAs without client-side
script support) or refer to the form in the previous (or rather, "next")
document using a visible _HTTP_ hyperlink. You then should use HTTP
techniques to have the resource requested from the server again instead
from the local cache with the latter approach:

<http://www.mnot.net/cache_docs/>
[...]
<script language="JavaS cript">
From HTML 4 on, the `language' attribute is deprecated for valid reasons
while the `type' attribute is required for the same reasons. As the latter
has proven to be sufficient, the above should read

<script type="text/javascript">
function Disable_All()
Using identifiers starting with capital letters for script items that are
not used as constructors is discouraged by several JS code style guidelines
to avoid confusion and unexpected side effects, and to increase legibility
of source code.
{
document.frmPos t.employeename. className="disa bled"; ^
Blocks of source code should be properly indented using a reasonable number
of spaces, where multiples of 2 and/or 4 are recommended, especially when
it is posted to a public medium like this newsgroup.
document.frmPos t.employeename. disabled = true ^
While the automatic semicolon insertion feature of the language
allows to omit semicolons, it is highly recommended to include
them explicitely and consequently anyway to avoid "odd" script
behavior not easily understandable to beginners.
[...]
for (var i = 0;i<8;i++){
document.frmPos t.elements.hwre qested[i].disabled = true;
}
1. DOM scripts should make use of standards compliant referencing whenever
possible, and always if that is also backwards compatible. The above
therefore should read

document.forms["frmPost"].elements["employeena me"].className="dis abled";
....
for (var i = 0;i<8;i++)
{
document.forms["frmPost"].elements["hwreqested "][i].disabled = true;
}

instead. Note that .disabled=true is not supposed to work in XHTML,
you (also) need .disabled="disa bled" there.

2. Repeated lookups of the same object reference should be avoided
as such is inefficient; assign the reference to a local variable
and use that variable instead. If you use references within
a repeated block, assign the reference outside of the repeated
block if possible and feasible:

var
es = document.forms["frmPost"].elements,
hwreq = es["hwreqested "];

es["employeena me"].className = "disabled";
...

for (var i = 0; i < 8; i++)
{
hwreq[i].disabled = true;
}
</Script>
While the case of an element type identifier case does not matter in SGML
based markup languages like HTML, it does matter in XML based markup
languages like XHTML. Therefore, one should develop the habit of having
element type and attribute identifiers, and attribute values lowercased
where possible; especially, one should avoid mixing case with(in) the
start tag and the end tag of an element.
<body onLoad="Disable _All();">


See above for how this event handler attribute value affects usability
of the document.
PointedEars
Jul 23 '05 #2
Thomas 'PointedEars' Lahn wrote:
<snip>
for (var i = 0;i<8;i++)
{
document.forms["frmPost"].elements["hwreqested "][i].disabled = true;
}

instead. Note that .disabled=true is not supposed to work in
XHTML, you (also) need .disabled="disa bled" there.

<snip>

..disabled = true - most certainly is expected to work in an XHTML DOM.
The HTML DOM specification states that the disabled property of the
HTMLInputElemen t interface is a boolean property, and includes no
special notes for XHTML DOM implementations .

The - disabled - attribute in XHTML mark-up might differ from HTML but
there is no reason to expect that to carry through to the type, and
value, of the - disabled - property in the DOM, especially as the
attribute has no representation of not-disabled.

Richard.
Jul 23 '05 #3
Thomas 'PointedEars' Lahn wrote:
[...]
2. because you do not have control over the user agent's cache usage,
you cannot assume any of the described behavior of a Back (button)
feature, if there is any. Especially, onload scripts are not executed
when using that feature and the document is accessed on the local cache.


onload scripts are executed[1] in both IE and Firefox when the 'back'
and 'forward' buttons are used.

[1] insert the usual caveat regarding script execution where the
browser can't or won't execute the script.

[...]
--
Rob
Jul 23 '05 #4
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
<snip>
for (var i = 0;i<8;i++)
{
document.forms["frmPost"].elements["hwreqested "][i].disabled = true;
}

instead. Note that .disabled=true is not supposed to work in
XHTML, you (also) need .disabled="disa bled" there.

<snip>

.disabled = true - most certainly is expected to work in an XHTML DOM.
The HTML DOM specification states that the disabled property of the
HTMLInputElemen t interface is a boolean property, and includes no
special notes for XHTML DOM implementations .


Right. However, it reproducably does not work in some implementations
I have encountered when reading newsgroups. Yes, such could be considered
borken. No, they are not this seldom. No, I also would have to use Google
to find out what they exactly were. Sorry.
PointedEars
Jul 23 '05 #5
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
<snip>
for (var i = 0;i<8;i++)
{
document.forms["frmPost"].elements["hwreqested "][i].disabled =
true; }

instead. Note that .disabled=true is not supposed to work in
XHTML, you (also) need .disabled="disa bled" there.

<snip>

.disabled = true - most certainly is expected to work in an XHTML
DOM. The HTML DOM specification states that the disabled property
of the HTMLInputElemen t interface is a boolean property, and
includes no special notes for XHTML DOM implementations .


Right. However, it reproducably does not work in some
implementations I have encountered when reading newsgroups.
Yes, such could be considered borken. No, they are not this
seldom. No, I also would have to use Google to find out what
they exactly were. Sorry.


Not that reproducible without the name of the UA.

Richard.
Jul 23 '05 #6

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

Similar topics

3
2998
by: Ray Torres | last post by:
I would appreciate any help with the following problem. I have several different htm pages with (simalar) forms that are processed by the same PHP script. If there is data missing on the form, the script displays an error page (using the header() function) and informs the user to press the browser's "Back" button. The problem is that when the user goes back to the form's htm page, all the fields are blank. I would like all
3
2058
by: Greg Alaksdjflk | last post by:
How do I create a form that allows one to submit a form, then press the "BACK" button on the browser, and allow the user to see the data he posted? It seems as though this information is lost. For instance, <form method="get" action="/contact/default.asp" name="ContactForm"> .... </form>
4
2197
by: Food Groupy | last post by:
Hi... I use a function something like this, <a href="javascript:history.back();">Return to original page</a> to give people a "back" option sometimes on pages. Is there any way of directing them back to a particular named anchor on the last page?
5
3070
by: Ma³y Piotruœ | last post by:
Hello, (Sorry for my english.) I am new to HTML/JavaScript/CSS. I would like to ask for help with such a problem: I need to create a href link working like "back" button (I know this is not recommended by it's not my idea, and I must respect this requirement.) I did it this way: <a href="javascript:history.back()">Back</a>
2
1560
by: Barry Fitzgerald | last post by:
I have a site that requires a large number of pages to complete the entry of all the information. The information collected also varies depending on some of the data entered. I would like to prevent the back button from working. Can that be done? Can I prevent a page from displaying when the back button is clicked somehow, perhaps by requiring that it always be loaded from the web sever and not cached on the user pc? -- Barry...
2
3806
by: Leszek Taratuta | last post by:
Hello, I am using the following code to prevent users to see the previous pages: Response.CacheControl = "no-cache"; Response.AddHeader( "Pragma", "no-cache" ); Response.Expires = -1; When users select the "Back" button in IE, they see the message:
2
1339
by: Amelyan | last post by:
Sometimes, when I hit the back button on IE, my Page_Load function gets executed. But sometimes, it doesn't. What controls that? Thanks, -Amelyan
0
1994
by: Michael Nemtsev | last post by:
Hi, I need to stay on the current page even if user clicks "BACK" in browser. Opera is very stubborn in attemp of turning cached page off, and using current. Does anybody know the way how to say Opera not to show previous page when I click "Back" button and show current page. Which meta info should be specified?! Currently I use the following code, which works fine with IE and FireFox (no previously cached page is shown)
0
8863
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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
9384
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
9238
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...
0
8052
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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
2
2602
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.