Add readonly attribute dynamically to input tag

Discussion in 'Javascript' started by upersson@consit.dk, Jun 30, 2005.

  1. Guest

    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
     
    , Jun 30, 2005
    #1
    1. Advertising

  2. Mick White Guest

    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
     
    Mick White, Jun 30, 2005
    #2
    1. Advertising

  3. Mick White Guest

    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
     
    Mick White, Jun 30, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    871
    John C. Bollinger
    Jan 27, 2006
  2. David Wright

    input attribute for the input tag?

    David Wright, Dec 19, 2006, in forum: HTML
    Replies:
    1
    Views:
    345
    Jukka K. Korpela
    Dec 20, 2006
  3. Cecil Westerhof

    How to get a readonly tag into an input

    Cecil Westerhof, Feb 8, 2007, in forum: XML
    Replies:
    4
    Views:
    659
    Cecil Westerhof
    Feb 9, 2007
  4. Sree

    VS marks 'readonly'attribute as error for input tag

    Sree, Feb 24, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    160
    Guest
    Feb 25, 2004
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    2,019
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page