Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Add readonly attribute dynamically to input tag

Reply
Thread Tools

Add readonly attribute dynamically to input tag

 
 
upersson@consit.dk
Guest
Posts: n/a
 
      06-30-2005
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
 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      06-30-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      06-30-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get a readonly tag into an input Cecil Westerhof XML 4 02-09-2007 05:51 AM
input attribute for the input tag? David Wright HTML 1 12-20-2006 06:00 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
ASP.NET Readonly panel function with readonly checkbox, readonly radiobutton Jonathan Hyatt ASP .Net Web Controls 1 06-08-2004 07:42 PM
VS marks 'readonly'attribute as error for input tag Sree ASP .Net Web Controls 2 02-25-2004 05:24 PM



Advertisments