[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Is css the best way to make a form editable versus non-editable based on permissions?

I have a form.  Based on permissions, it will either be
- readonly;
- partially editable (some fields will remain uneditable);
- fully editable (all fields will be editable)

Is css *the* way to do this, or are there more technical, programmatic ways to do this?  I am inclined to use css but want to make sure that there might not be another way.

Please provide a pseudo-code sample when replying if possible ...

  • 2
  • 2
1 Solution
CSS will enable you to hide/show some of your fields.
If this is what you need, then it is definitely the best way to do this. Use class names to hide of show with display or visibility attributes.
If you do not want to hide them but just disabling them, you will have to add an attribute to the field you do not want to be edited (disabled="true"), either directly in the tag:

<input type="text" disabled="true"/>

or with Javascript:

document.forms["nameOfMyForm"].elements["nameOfFieldToBeDisabled"].disabled = true;
pingdeeAuthor Commented:
This leads me to better clarity - indeed, I do not want to hide fields but simply make them read-only or disabled.  Is disabled the best bet, or is read-only?  
I don't think that read-only is cross browser, but ie only.
disabled is compatible with all browsers.
But you must be aware that a disabled field will not be posted with the form.
So, if you need to get back their values, you would have to use input hidden with the same name containing the same value.
pingdeeAuthor Commented:
thanks, smaccari - i think that i got all i need :)

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now