Add readonly attribute dynamically to input tag

U

upersson

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
 
M

Mick White

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
 
M

Mick White

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top