473,795 Members | 3,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Restricting user input without "disabled"

Hi

I have two "totals" inputs whose values are dynamically calculated.
For obvious reasons I don't want users to be able to edit the
information in these. However, I do want this total passed to the next
page so I can store it. When I set the input to "disabled" it does not
pass it's value. Is there another way I can do this?

I was thinking about using an onFocus event to set the focus to
another field but is this the best option? Any help appreciated.

cheers

Jeremy
Jul 20 '05 #1
5 2598
Hi Jeremy,

you can do this disabling the field and creating another
hidden field containing the same value.

Or you can - if the total sum is calculated with values
of the other fields - calculate the sum later.

Or, another possibility which should work is putting
this into the submit button:

onclick="docume nt.getElementBy Id('idOfTheDisa bledField').dis abled = 'false';

Greetz
Paul.

Jul 20 '05 #2
> Why the use of getElementById when you can make it work in any browser that
supports forms?


Actually, I don't know why. Because I always use getElementById,
the force of habit. Is there any reason why the other way is better?
Ok, you don't have to assign an ID to the input.

If I use forms I am used to write document.forms['name_or_index']...
But its exactly the same, or is there a difference?
Which of those ways is the recommended one by the W3C?
(Or ECMA, but thats DOM I think)

Regards,
Paul.
Jul 20 '05 #3
Paul Wellner Bou <pa**********@u nited-scripts.com> writes:
Actually, I don't know why. Because I always use getElementById,
the force of habit. Is there any reason why the other way is better?
The document.forms collection is supported in all browsers since
Netscape 2, while getElementById is only supported in modern browsers
(IE 5+,Mozilla, Opera 4+ (at least)). Both are in the W3C DOM.
If I use forms I am used to write document.forms['name_or_index']...
Good! I always recommed using that instead of the shorthand. To get an
element, you write
document.forms['formName'].elements['elemName']
or
document.forms. formName.elemen ts.elemName
(I prefer the former, to keep the namespaces separate.)

Most browsers accept some shorthands for both the forms and elements
collections:
document.formNa me.elemName
or (notably IE)
formName.elemNa me
(i.e., window.formName .elemName)
None of these shorthands are part of the W3C DOM specification, so
it is safer to write write it all out.
But its exactly the same, or is there a difference?
Which of those ways is the recommended one by the W3C?
both document.getEle mentById and document.forms are W3C DOM.
The getElementById is DOM Core, while document.forms is DOM HTML
(Core is a W3C Recommendation since Nov 13, 2001, while DOM HTML
was only made a recommendation in January 2003, but now they are
equal).

The difference is in browser support. Using the forms collection
will work in all browsers, even the old ones.
(Or ECMA, but thats DOM I think)

It is.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:vf******** **@hotpop.com.. .
<snip>
Most browsers accept some shorthands for both the forms and
elements collections:
document.formNa me.elemName
or (notably IE)
formName.elemNa me
(i.e., window.formName .elemName)
None of these shorthands are part of the W3C DOM
specificatio n, so it is safer to write write it all out.

<snip>

While non of these shorthand versions are specified, the HTML DOM level
2 specification does appear to allow a short hand of referring to the
element as a named property of the form object:-

FormObject['elemName']

- or -

FormObject.elem Name

- as the spec describes the form element as <quote> The FORM element
encompasses behavior similar to a collection and an element. It provides
direct access to the contained form controls as well as the attributes
of the form element.</quote>.

I, like you, prefer to use the longer form and access via the elements
collection using:-

document.forms['formName'].elements['elName']

- for exactly the same reasons of code clarity (and universal browser
support), and if it will be a problem that that form resolves slightly
slower than a shortcut form then that can usually be overcome by caching
a reference to the elements collection and subsequently referring to
named elements relative to that.

var els = document.forms['formName'].elements;
for(var c = 0;c < 10000;c++){
els['elName'+c].value = ''; //clear 10000 consecutively named
//elements without resolving the
//form object or its elements
//collection for each.
}

Richard.
Jul 20 '05 #5
Jeremy Langworthy wrote:
Hi

I have two "totals" inputs whose values are dynamically calculated.
For obvious reasons I don't want users to be able to edit the
information in these. However, I do want this total passed to the next
page so I can store it. When I set the input to "disabled" it does not
pass it's value. Is there another way I can do this?

I was thinking about using an onFocus event to set the focus to
another field but is this the best option? Any help appreciated.

cheers

Jeremy


While all the information provided in response to this post was helpful, I
think everyone missed the most important point to make. Please do not rely
on any of the client-side code provided to "protect" these values from
being changed by the user. There are any number of things that a user can
do to submit "fake" values to your server. Your server-side processing
should ensure that the totals or other information passed to it are
rational and reasonable.

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #6

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

Similar topics

2
3604
by: Askari | last post by:
Hi, I do a "perso"widget where have two scrolls (one vertical, one horizontal) for a canvas. When, the first time, I added widget in the canvas, the scroll self-ajust and when I move scrollbar, the surface's canvas "moved". But when I deleted (.destroy) this first widgets and that a added other widget, the scrollBar become disabled (ajust for no scroll on the canvas). What/where is the problem?
2
5466
by: CES | last post by:
All, I'm at a loss, the code below works in IE but not in Netscape and I'm unskilled enough not to know why. Essentially this code looks thru all of the form fields and if the input box has a attribute of disabled="true", attribute would only be present if the field was disabled, then the label field's class is changed to a grayed out color. --- The first problem seems to be with the v==true statement, I've tried
1
6687
by: Kruse | last post by:
Hi, Is Possible to alter the "disabled" style? I have got <input name="test" value="1" disabled> This makes the input field gray and shadow.
1
11631
by: Ittay Dror | last post by:
Hi, I have a form with various elements which, according to changes in values become enabled or disabled. The disabled elements are normally not submitted, but I wish they were. How can I go about making elements appear to be disabled, but still send them when the form is submitted. Thanx,
5
2478
by: Mark Hannon | last post by:
I have been researching the "disabled" property for form data and wanted to know: - Does the disabled property supress the form item from being submitted? - Can the disabled property be applied when the submit button is pressed? I am designing a PayPal order page that will have 4 items, each with a 3-character text box where the customer will enter quantity. The default value will be "0." I want to be able to test whether the
0
1239
by: Dana Epp | last post by:
Anyone know how to set the "Disabled" imagelist in a C# Toolbar? Although the Microsoft's Toolbar ActiveX control in the mscomctl.ocx has such a property, there doesn't seem to be one for the C# version. Anyone know a work around for this? --- Regards, Dana M. Epp http://silverstr.ufies.org/blog/]
1
2683
by: Morten Plathe | last post by:
Hi, Is there a way to override the shadowed (grey) backcolor of a textbox when the textbox is disabled for input (textbox.enabled = false) ? In some cases I want to have a custom backcolor when the textbox is disabled. The same question applies for a listview. When the listview is disabled, the backcolor of the listview turns grey (shadowed) for the area which is not filled
1
3809
by: R.A.M. | last post by:
Hello, I have started programming ASP.NET application using SQL Server 2005 Express Edition. The problem is that when C# code tries to access aspnetdb database, for example: System.Security.Principal.IPrincipal user = HttpContext.Current.User; if (user.IsInRole("Kierownik")) // HERE PROBLEM ....then the following run-time error occurs:
0
1275
by: Curious | last post by:
Hi, I try to set up debugging environment in Visual Studio 2003. So I open the Properties of the project and select "Debugging". I'll need to at first enter "C:\Program Files\AutoTrade\MyTools \TSF_Server_1.exe" in the "Debug Mode" entry. However, this entry is disabled/greyed out. I'm unable to enter anything. Any advice on how to get this entry enabled?
0
9519
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
10214
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
10164
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
10001
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...
0
9042
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...
0
6780
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3723
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.