Disabling changes to a form field

Posted on 2010-01-06
Last Modified: 2012-05-08
I have a simple form setup and I'm using PHP to read the form and send the data to a text file.  I only want the user to able to modify a few of the fields.  The rest I've set to have values.  I want to set my page up so that the user can not modify the fields that already have values.  Here's what I tried:

<input type="text" name="Field1" size="30" maxlength="2" value="H0" id="Field1" disabled />

The disabled prevents the user from entering anything into the field and the field still shows my value of H0.  However, PHP doesn't see any text in the field and therefore does not store anything to my text file.

So is there a simple CSS/JS script I could use to stop users from entering characters into specific fields?
Question by:TacomaVA
    LVL 4

    Accepted Solution

    Can you not just set the values in the disabled text boxes as default values in your php script?
    Like this (crude, but trying to make a point):


       $_POST["Field1"] = "H0";

    LVL 4

    Expert Comment

    If not, you can have your textbox watch for any keyboard strokes, and return null each time. Not sure exactly how that would be coded, but it's not easy. I've done something similar, but a LONG time ago.
    LVL 81

    Assisted Solution

    Hello TacomaVA,

    Use : readonly="readonly"
    Not : disabled


    <input name="Field1" type="text" id="Field1" value="H0" size="30" maxlength="2" readonly="readonly" />

    Open in new window


    Author Comment

    Thank you, both of you!  Both solutions worked!
    LVL 81

    Expert Comment

    Thanks for the points! Happy new year!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    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…
    CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    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…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now