Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I Disable an input element but still have Black text? 1

Status
Not open for further replies.

jsteph

Technical User
Oct 24, 2002
2,562
US
I want the element to look normal, but not be editable. Do I have to trap keystroks for this? If so, how? Thanks,
--Jim
 
Try setting the readonly property:
Code:
<input type="text" [!]readonly="readonly"[/!] value="try to type over me" />

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
one javascript workaround is to use the onfocus() event:

Code:
<input type="text" name="t1" onfocus="this.blur();" />

however, that will only work with javascript enabled, and, that really belongs in the javascript forum. i guess you could say i pulled a "j4606".

you cannot style a disabled element differently - the gray, i'm afraid, you're stuck with.

you can possibly style a transparent div over the input element, but i don't think that would eliminate tabbing to the field.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
As a follow-up, I ended up with an alternative to the readonly--which does work as advertised, but I wanted to be able to put the cursor in the controls because the users like to tab through the fields to navigate.

So a keypress event, which takes the event.keycode and sets it null works here--it doesn't nullify tabs, etc, only printable chars.
--Jim
 
cLFlaVA said:
however, that will only work with javascript enabled, and, that really belongs in the javascript forum. i guess you could say i pulled a "j4606".
[sadeyes]


I don't know the answer but my good friend Google does.
 
Hah,I know, It gave me a chuckle when i saw my name i had to do a double take. unfortunatly work has me busy atm so i just post smileys. It's acctually refreshing to see some personalities behind the screen names and I enjoy the jabs you and kaht take at each other. Hopefully no one will pull a 'j4606' while I'm gone.

I don't know the answer but my good friend Google does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top