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

Posted on 2006-04-21
Last Modified: 2010-04-06
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 ...

Question by:pingdee
    LVL 9

    Expert Comment

    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;

    Author Comment

    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?  
    LVL 9

    Accepted Solution

    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.

    Author Comment

    thanks, smaccari - i think that i got all i need :)

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now