467,877 Members | 1,283 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

Add readonly attribute dynamically to input tag

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
Jul 23 '05 #1
  • viewed: 4235
Share:
2 Replies
up******@consit.dk wrote:
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


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
Jul 23 '05 #2
Mick White wrote:

[snip]


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

That should be, of course:

function denyWritingPrivilegesToTextInputs(form)

Mick

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by kaeli | last post: by
2 posts views Thread by RN | last post: by
7 posts views Thread by Jimbo | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.