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

HTML questions...

Status
Not open for further replies.

aharrisreid

Programmer
Nov 17, 2000
312
0
0
GB
A couple of questions regarding creating web pages in HTML...

1. What is the difference between the readonly and disabled properties for input fields?

2. Is there any easy way to disable (or make readonly) all objects in a HTML page (or within a form on a page) without having to manually add the 'disabled' property to all objects on the page (I am using Dreamweaver)?

Many thanks,
Alan Harris-Reid
 
The major difference between readonly and disabled is their appearance. As I recall, readonly LOOKS normal, but you just can't enter data into it. Disabled is greyed out. I don't think either one are supported by all browsers.

You can loop thru all the objects in a form and set them disabled like this:
Code:
for ( x = 0; x < document.formname.elements.length; x++ ) {
   document.formname.elements[x].disabled = true;
}
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracy, thanks for the reply.

Is the code you posted JavaScript or HTML? I am a complete novice to JS, so I am not sure how to implement the code you supplied. Any help would be appreciated.

Also, what about the objects which don't have a 'disabled' property? Will they be ignored?

Many thanks,
Alan
 
It's javascript. You could put it in a function and call it onLoad or whereever you need it. The way it's set up, it will disable ALL fields on the form. I'm not sure how to tell if the field has a disabled property or not. Anyhow, here's how the code would look as a function:
Code:
<script language=&quot;Javascript&quot;>
function disableFields() {
   for ( x = 0; x < document.formname.elements.length; x++ ) {
      document.formname.elements[x].disabled = true;
   }
}
</script>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
To the best of my knowledge, IE supports both readonly and disabled. Netscape, however, only supports disabled. If I'm wrong, Please let me know.

Also, disabled fields are not passed back to the server while readonly fields are.
 
Thanks! I complete forgot to mention the part about which fields are passed to the server. Unfortunately, NOT a minor oversight! I think you're correct about who supports what, but I'm too lazy to test it right now. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top