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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking out access to form field without using disabled

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
Hi All,

I am sure I have done this in the past but am drawing a blank.
I want to lock out a form field so that it cannot be edited but not use the disabled property on it so as to avoid the change in background and text colors.

In my code I am starting with all boxes locked and then unlocking select ones based on who is viewing the page.
So I will be displaying the page then executing the code to unlock appropriate boxes and do not want to have to play with the other attributes at the same time.

Any easy way to accomplish this?

Thanks.

Paranoid? ME?? WHO WANTS TO KNOW????
 
Probably not what you're looking for but just incase.

Code:
<html>
<body>
<form>
<input type="checkbox" onclick="return false;" checked>
<input type="text" onkeypress="return false;">
</form>
</body>
</html>
 
Add [tt]readonly="readonly"[/tt] to your locked input elements.
 
Thanks Fendal but not what I am looking for.
Some of these fields actually have onclick or onchange events that may have to be used.

I found I can use the readonly property to do part of what I want to do but it has the drawback of allowing the field to get focus so my events fire even though the field is locked out.

Not all of the fields have events so I may just add code in my event functions to test if the readonly property is set and abandon the event action if it is.

Readonly does not apply to checkboxes either so for those I still have to use Disabled but that's not too bad a tradeoff.

This page could have many different methods of displaying depending on who is viewing it. Some people get extra menus, fields or option buttons and others have limited access to some of the form fields. I want to try and get it all into a single page and alter only the characteristics specific to the current viewer but that means hiding/showing options and locking or unlocking various fields.
Rather than building multiple possible versions of the same section of the page I want to just toggle attributes for the existing one and keep the code simpler and cleaner.


Paranoid? ME?? WHO WANTS TO KNOW????
 
Thanks Vragabond, I have just started using readonly.
It has drawbacks that disabled does not as I mention above but I think I can make it work. It is still less work than trying to alter the background and text color attributes as well as the disabled attribute every time. Or trying to use a stylesheet to keep the disabled fields looking the same. In some cases I want them to change so...


Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top