473,387 Members | 1,771 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,387 software developers and data experts.

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="JavaScript">
function Disable_All()
{
document.frmPost.employeename.className="disabled" ;
document.frmPost.employeename.disabled = true
document.frmPost.copyfromemployee.className="disab led";
document.frmPost.copyfromemployee.disabled = true
document.frmPost.effdate.className="disabled";
document.frmPost.effdate.disabled = true
document.frmPost.branch.className="disabled";
document.frmPost.branch.disabled = true
document.frmPost.jobtitle.className="disabled";
document.frmPost.jobtitle.disabled = true
document.frmPost.defprinter.className="disabled";
document.frmPost.defprinter.disabled = true
document.frmPost.printerdesc.className="disabled";
document.frmPost.printerdesc.disabled = true
document.frmPost.extraservice.className="disabled" ;
document.frmPost.extraservice.disabled = true
document.frmPost.assistance.className="disabled";
document.frmPost.assistance.disabled = true
for (var i = 0;i<8;i++){
document.frmPost.elements.hwreqested[i].disabled = true;
}
for (var i = 0;i<5;i++){
document.frmPost.elements.swrequested[i].disabled = true;
}
}
</Script>
<body onLoad="Disable_All();">

Jul 23 '05 #1
5 2392
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.referrer 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.referrer 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="JavaScript">
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.frmPost.employeename.className="disabled" ; ^
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.frmPost.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.frmPost.elements.hwreqested[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["employeename"].className="disabled";
....
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="disabled" 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["employeename"].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="disabled" 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
HTMLInputElement 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="disabled" 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
HTMLInputElement 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="disabled" 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 HTMLInputElement 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
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,...
3
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. ...
4
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...
5
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...
2
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...
2
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...
2
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
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.