473,594 Members | 2,720 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 2426
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
2985
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
2055
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
2190
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
3065
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
1553
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
3795
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
1337
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
1985
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
7876
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
8372
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...
1
8003
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8234
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
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
3859
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.