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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    India
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing the value of a disabled text field

    Is there any way I can pass the value in a disabled text field without creating a hidden field?

    Thanks.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    I thought you could - doesn't it show up in

    Response.Write(String(Request.Form))

    ?

  • #3
    New Coder
    Join Date
    Sep 2002
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Disabled fields are ignored with form post/gets.

    The trick is to set the field as "ReadOnly". I use a little javascript & CSS to imitate an Enabled/Disabled field.

    document.getElementById('txtField1').className=((oCheckField.checked)?'EnabledField':'DisabledField' );
    document.getElementById('txtField1').readOnly=((oCheckField.checked)?false:true);

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <% OPTION EXPLICIT %>
    <html>
    <style type="text/css">
    <!--
    .DisabledField {
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	color: #333333;
    	background-color: #999999;
    }
    .EnabledField {
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	color: #000000;
    	background-color: #FFFFFF;
    }
    -->
    </style>
    <script language="JavaScript">
    function SetField(){
    	oCheckField=document.getElementById('chkField')
    	document.getElementById('txtField1').className=((oCheckField.checked)?'EnabledField':'DisabledField');
    	document.getElementById('txtField1').readOnly=((oCheckField.checked)?false:true);
    }
    </script>
    </head>
    <body>
    <%= CStr("ReturnValue: " & request.Form("txtField1")) & "<br>") %>
    <form action="Return.asp" method="post" name="from1" onclick="SetField()" class="EnabledField">
    	<input name="chkField" type="checkbox" id="chkField" value="" />
    	<input name="txtField1" id="txtField1" type="text" value="this is a test value" size="25" class="DisabledField" readonly="true">
    	<input name="btnSubmit" type="submit">
    </form>
    </body>
    </html>
    The value gets passed with HTTPPost/HTTPGet but the user cannot change the value.

    Hope this helps
    a credit card for a newbie from Amex: The Amex Blue card would like to start developing a credit history.


  •  

    Posting Permissions

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