Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    making text box read only..

    dear all

    i have some read only text box which i want to get in write mode
    the code i am trying is..
    function f2(txt1,txt2,txt3)
    {
    document.form1.txt1.readOnly=false;
    document.form1.txt2.readOnly=false;
    document.form1.txt3.readOnly=false;
    }
    <input type="text" value="<%=rset.getString(1)%>" readonly id="tex" class="tb2" name="u_name_0"></td>
    <td><input type="text" value="<%=rset.getString(2)%>" readonly class="tb2" name="u_pass_0"></td>
    <td><input type="text" value="<%=rset.getString(3)%>" readonly class="tb2" name="u_role_0"></td>
    <td><input type="submit" value="delete" name="submit_<%= i%>" class="tb3"></td>
    <td><input type="button" value="update" onClick="f2('u_name_0','u_pass_0','u_role_0')"></td>

    but its not working..
    some body help me out..

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Code:
    <script type = "text/javascript">
    function f2(){
    document.form1.u_name_0.readOnly=false;
    document.form1.u_pass_0.readOnly=false;
    document.form1.u_role_0.readOnly=false;
    }
    </script>
    <form name = "form1">
    <input type="text" value="<%=rset.getString(1)%>" readonly id="tex" class="tb2" name="u_name_0"></td>
    <td><input type="text" value="<%=rset.getString(2)%>" readonly class="tb2" name="u_pass_0"></td>
    <td><input type="text" value="<%=rset.getString(3)%>" readonly class="tb2" name="u_role_0"></td>
    <td><input type="submit" value="delete" name="submit_<%= i%>" class="tb3"></td>
    <td><input type="button" value="update" onClick="f2()"></td>
    
    </form>

    Quizmaster: Which English king succeeded Henry VIII?
    Contestant: Henry VII.

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    <script type = "text/javascript">
    function f2(){
    document.form1.u_name_0.readOnly=false;
    document.form1.u_pass_0.readOnly=false;
    document.form1.u_role_0.readOnly=false;
    }
    </script>
    <form name = "form1">
    <input type="text" value="<%=rset.getString(1)%>" readonly id="tex" class="tb2" name="u_name_0"></td>
    <td><input type="text" value="<%=rset.getString(2)%>" readonly class="tb2" name="u_pass_0"></td>
    <td><input type="text" value="<%=rset.getString(3)%>" readonly class="tb2" name="u_role_0"></td>
    <td><input type="submit" value="delete" name="submit_<%= i%>" class="tb3"></td>
    <td><input type="button" value="update" onClick="f2()"></td>
    
    </form>

    Quizmaster: Which English king succeeded Henry VIII?
    Contestant: Henry VII.
    thanks dear but..
    In my application dynamically text box are creating so i must hve to pass the text box name .
    i cant call the name statically..

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    To make a form element readonly
    Code:
    element.setAttribute('readOnly','readonly');
    To make a form element editable again:
    Code:
    element.removeAttribute('readOnly');
    And the safe standard HTML/XHTML syntax for the readonly attribute is:
    Code:
    <element readonly="readonly">
    Because in strict DTD, all the HTML attributes must have a value, but that value may not be a Boolean (because HTML values of all the attributes are strings). In other elder DTD (transitional HTML), it does not matter.
    Last edited by Kor; 07-30-2010 at 12:49 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,023
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Everything Kor said is true, but doesn't at all answer your question.

    If you are *NOT* using STRICT DTD, then this will do the job:

    Code:
    function f2(name1, name2, name3 )
    {
        document.form1.elements[name1].readOnly=false;
        document.form1.elements[name2].readOnly=false;
        document.form1.elements[name3].readOnly=false;
    }
    ...
    <td><input type="button" value="update" onClick="f2('u_name_0','u_pass_0','u_role_0')"></td>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •