UPDATE! [X]HTML HowTo: Disable a text box.

The Code

A few things came up after I submitted the first post.

Say you have code similar to: <input type="text" name="username" id="username" value="Nick" disabled="disabled" />

Then, the user submits the form and you go to access ‘username’ via $username = $_POST['username']

Well, you might be surprised to find out that disabled="disabled" actually disables the value of the variable $_POST['username'].

Instead, if you want to keep the value of the text input, you should use the following code: <input type="text" name="username" id="username" value="Nick" readonly="readonly" />

Now, when you go to access $_POST['username'], you should still have the value of the input.

Graphical Differences

Disabled

Readonly

Happy Coding!

Nick

Leave a Reply

You must be logged in to post a comment.


This is a free Wordpress template provided by Mathew Browne | Web Design | SEO