August 25, 2013

A disabled but readable input

Fabián’s Question:

So I have two forms, one is for creating and the other for editing. Both using method="post".

There’s one difference between both, which is the code_product, that is generated via php’s rand() function, used only when creating a product (so there’s no code_product input here).

And when editing it, the code_product value is shown inside of an additional input at the top of the entire form.

Objective: code_product‘s input mustn’t be edited.

Problem: Using the disabled attribute makes it unreadable for php too.

Avoiding the asp.net (mentioned in another post), is there another way to make it uneditable, through css or javascript?

Add an attribute called readonly to your input elements. This way it cant be edited but still viewed as normal.

<input type="text" readonly />

For older browsers, you will need

<input type="text" readonly="readonly" />

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!