Never Use Computed for Display Fields Again!

You Can View User Feedback To This Tip

This tip disables any fields or buttons on your form.

Developers have always had this problem of having to use computed for display fields for their corresponding editable fields. Suppose I do not want to use author fields, my default access is "Editor" and want that certain people should not be able to change certain field values at a particular status in the workflow. At the same time I want the user to be able to enter data in some other fields and click on certain buttons only. In Notes I would use controlled access sections. On the web, we all know how controlled access sections look like! So we tend to use computed for display fields showing the value of the original editable field so that the user does not change any specific data. Instead, wouldn't it be nice if we could just DISABLE the editable fields or buttons on that particular status, so that information was for read-only purposes only. Well, try this:

(1) In the <HTML> Tab of your field/button enter a 'Name' in the 
Name field. Let's sat 'TestName' (2) Use the folowing code: document.forms[0].TestName.disabled = true This will disable that element on the form. (3) To enable, you simply say: document.forms[0].TestName.disabled = false. This way you can disable/enable fields/buttons etc... on your form.


  • Further to this tip, which is very useful at times and certainly reduces development time/Fields....

    You can also just Compute the word "DISABLED" into the HTML Attributes of the field. This code can then made more flexible/powerful by the use of @Formulae.....

    Code: If you want a field to only be editable by users with the Admin Roles then you can do this...

    In the HTML attributes section of the field... @If(@IsMember("[Admin]"; @UserRoles); ""; "DISABLED")

    The disabled field I have found can be confusing to users as they see a field but do not understand why they can't edit it. So I compromised by using a stylesheet to highlight the fields which are DISABLED - you can compute the HTML attributes to contain the class name "cDisabled" and control the look fo the field - here is an example..

    @If(@IsMember("[Admin]"; @UserRoles); ""; "DISABLED class="cDisabled"")
    and in the HTMLHEAD (or as passthru on the form) you can add
    	border-width: 0px
    Full HTML Example
    	<title>DISABLED Demo</title>
    	border-width: 0px
    Editable Field
    <input type="Text" name="Field1" value="Edit Me">
    DISABLED Field
    <input type="Text" name="Field2" value="Disabled" DISABLED class="cDisabled">

    The MAJOR drawback for this method is that the DISABLED Tag (and the style sheet for that matter) is not supported in Netscape4 (works in Netscape 6.1) and any user can bypass the security by just using the netscape 4 browser...
    —Mark Roden

  • This tip isn't bad at all. If the user tries to use an older version of Netscape, you can simply us the blur property once you check if a version of Netscape is less than 6.1—Yoofi Ocran

This was first published in January 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.