Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / June 2005



Tip: Looking for answers? Try searching our database.

Add readonly attribute dynamically to input tag

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
upersson@consit.dk - 30 Jun 2005 12:58 GMT
Hi!

When accessing my web page I build up the javascript and html
dynamically. Depending on an parameter I want to set all the fields
(input tags) readonly. How do I do this? Of course I can write if
statements to add different input tags with and without the readonly
attribute. But is it possible to write a javascript that onload search
the page and add readonly to all input tags?

Regards /Ulrika
Mick White - 30 Jun 2005 15:33 GMT
> Hi!
>
[quoted text clipped - 6 lines]
>
> Regards /Ulrika

function denyReadingPrivilegesToTextInputs(form){
  var f=form.length;
    while(f--){
      if(form.elements[f].type=="text"){
      form.elements[f].readOnly=true;
    }
  }
}

Note "readOnly" property, it's case sensative.
Mick
Mick White - 30 Jun 2005 15:38 GMT
[snip]

> function denyReadingPrivilegesToTextInputs(form){
>   var f=form.length;
[quoted text clipped - 4 lines]
>   }
> }

That should be, of course:

function denyWritingPrivilegesToTextInputs(form)

Mick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.