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

can textfield be disabled for editing?

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
0
0
US
Hi,all
currently I am working on online insurance renewal for our
old customers. My program will search the database and reload the original application info for a specific custom to the renewal form. They can change coverage period, address etc, but they cannot change birthdate and name etc.
Is there any way I can disable editing for certain fields which I don't want them to change?
thanks
Betty
 
2 ways:

1 (worse): write disabled or readonly in the tag (i.e. <input type="text" readonly disabled>)

2 (better): write the text as simple html, then write an <input type="hidden" value="WHATEVER"> in the background. It will look normal, submit with the rest of the form, and be fully stylable with CSS
 
thanks, Nevermoor. I probably have to go with worse one if there is no other better one. I don't want to use hidden field since these field info needs to be present to the customers too.
Betty
 
how about if we disable the text dynamically using vb script....?... can it be done?....

Thank you....
 
Nevermoor's suggestion #2 was not only to include a hidden field, but was to also display the information as basic HTML text.

The disabled flag doesn't work in all browsers, IIRC, and client-side script would be even worse, imo, because if a user had scripting turned off then they'd be able to edit the fields, yet you (probably) wouldn't submit them to the database, and the user would be very confused.
 
Using JavaScript

Code:
<input style="background-color:rbg(200,200,200);" name="somename" onFocus="formname.otherformelement.focus();">

First, this will put a gray background in the field giving it the apperance that it is disabled. Or any other opague color will do the trick.

Second, the javascript statement will never allow the user to get focus on that field. Simply put another form element, maybe the next one in line that the user can edit, in that javascript statement and as soon as the user clicks or tabs into your "disabled" field, it will automatically move the cursor to the next field.

Alternatively, you can alert the user of the issue if you want by adding the following to the onFocus method.

Code:
<input style="background-color:rbg(200,200,200);" name="somename" onFocus="alert('You may not edit this field.');formname.otherformelement.focus();">

This will pop up an alert notifying the user that the field is not available for edit and then move the cursor to another field after they click OK on the alert.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top