...

View Full Version : Passing the value of a disabled text field



codefox
01-21-2003, 03:15 PM
Is there any way I can pass the value in a disabled text field without creating a hidden field?

Thanks.

Spudhead
01-21-2003, 05:30 PM
I thought you could - doesn't it show up in

Response.Write(String(Request.Form))

?

aCcodeMonkey
01-21-2003, 10:57 PM
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);



<%@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 :cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum