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

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 2574
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="document.getElementById('idOfTheDisabledF ield').disabled = '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**********@united-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.elements.elemName
(I prefer the former, to keep the namespaces separate.)

Most browsers accept some shorthands for both the forms and elements
collections:
document.formName.elemName
or (notably IE)
formName.elemName
(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.getElementById 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.formName.elemName
or (notably IE)
formName.elemName
(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.

<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.elemName

- 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*****@agricoreunited.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
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,...
2
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...
1
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
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...
5
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...
0
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#...
1
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...
1
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:...
0
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.