Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > How to make a html control be read only?

Reply
Thread Tools

How to make a html control be read only?

 
 
Matt
Guest
Posts: n/a
 
      03-06-2004
How to make a html control (text box, checkbox, etc...) be read only?
For example, in the following text box code, value "Joe" is in text
box, but user still able to edit it. I don't want user able to edit
it.

<input type="TEXT" name="username" value="Joe">

Please advise!
 
Reply With Quote
 
 
 
 
PW
Guest
Posts: n/a
 
      03-06-2004

"Matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> How to make a html control (text box, checkbox, etc...) be read only?



Try using "disabled" . (see example below)

<input type=text name="Total" DISABLED value="" size="10" maxlength="10">

You can also try "readonly".

HTH,
PW





 
Reply With Quote
 
 
 
 
Toby A Inkster
Guest
Posts: n/a
 
      03-06-2004
PW wrote:

> "Matt" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
>> How to make a html control (text box, checkbox, etc...) be read only?

>
> Try using "disabled" . (see example below)
> <input type=text name="Total" DISABLED value="" size="10" maxlength="10">
> You can also try "readonly".


That is one possibility, but it begs the question of whether <input> is
really an appropriate element to use in the first place.

If Matt doesn't want the end user to be able to input a new value, why use
<input> at all. Why not (for example) use:

<span style="border: 1px solid black; padding:2px">Joe</span>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      03-06-2004
Toby A Inkster <(E-Mail Removed)> wrote:

>> Try using "disabled" . (see example below)
>> <input type=text name="Total" DISABLED value="" size="10"
>> maxlength="10"> You can also try "readonly".

>
> That is one possibility, but it begs the question of whether
> <input> is really an appropriate element to use in the first place.


Indeed. And I wouldn't advice anyone to give advice on such things
unless the advisor _knows_ the difference beteen disabled and readonly
and doesn't need to ask others to "try" it.

> If Matt doesn't want the end user to be able to input a new value,
> why use <input> at all. Why not (for example) use:
>
> <span style="border: 1px solid black; padding:2px">Joe</span>


That would show (when CSS is enabled) the word "Joe" in a box, which
would make it look a bit like an input field. I don't think that would
be adequate in most cases, since it would suggest that the user _can_
change it and it would mean that the string "Joe" is not passed to the
form handler (which might not be needed actually, but I doubt that).

***

The question was multiposted, so apparently the OP is not interested in
getting quickly the best possible answer. For others, here's a copy of
my response in alt.html.tags:

http://www.velocityreviews.com/forums/(E-Mail Removed) (Matt) wrote:

> How to make a html control (text box, checkbox, etc...) be read only?


Using the attribute readonly (or if you play the XHTML game,
readonly="readonly") in an <input> element. But by the specification,
it applies to elements with type="text" and type="password" only
(though browsers might be more liberal).

> For example, in the following text box code, value "Joe" is in text
> box, but user still able to edit it. I don't want user able to edit
> it.
>
> <input type="TEXT" name="username" value="Joe">


So why do you have the field there in the first place?

It's safer to use

<input type="hidden" name="username" value="Joe">
Username: Joe

partly because not quite all browsers support the readonly attribute,
partly because this makes it much clearer that the user is not expected
to change the username.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


 
Reply With Quote
 
Leif K-Brooks
Guest
Posts: n/a
 
      03-06-2004
Matt wrote:
> How to make a html control (text box, checkbox, etc...) be read only?
> For example, in the following text box code, value "Joe" is in text
> box, but user still able to edit it. I don't want user able to edit
> it.


Why do you want to do that? Input boxes are for _input_, not display.
Why not put "Joe" on the page as normal text?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
open and read functions (can't make 'read' work..) ferbar C Programming 9 09-25-2005 07:52 AM
Help on HTML server control vs HTML control =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= ASP .Net 5 09-15-2005 07:51 PM
How to read the BODY of HTML file from another HTML file using javascript? Dhanasankar S via DotNetMonster.com ASP .Net 0 02-26-2005 10:58 AM
Is there any way to make a SELECT field in HTML as a read only field? datactrl Javascript 4 05-20-2004 01:25 AM
HTML Client Control versus. HTML Server Control versus. Web Server Control Matthew Louden ASP .Net 1 10-11-2003 07:09 PM



Advertisments