Reputation: 23
I have used a simple textbox, which is not working in IE 8. By default my textbox is disabled and when I click check on the checkbox, it should get enabled. But my textbox is not only getting enabled and disabled.
Please see the textbox property for your reference:
<asp:TextBox ID="txtAmount" runat="server" class="txtfld-popup1" MaxLength="5"
onkeypress="if(event.keyCode<48 || event.keyCode>57)event.returnValue=false;"
Enabled="false"></asp:TextBox>
<asp:CheckBox ID="chkInvestmentLoan" runat="server" CssClass="check"
OnChange="javascript:enableTextBox();" />
<script type="text/javascript">
function enableTextBox() {
if (document.getElementById("chkCropLoan").checked == true)
document.getElementById("txtAmount").disabled = false;
</script>
Upvotes: 1
Views: 283
Reputation: 13063
Your function is missing a closing brace }
function enableTextBox() {
if (document.getElementById("chkCropLoan").checked == true)
document.getElementById("txtAmount").disabled = false;
}
The ID is different from your markup
<asp:CheckBox ID="chkInvestmentLoan" />
vs:
document.getElementById("chkCropLoan")
Upvotes: 3
Reputation: 19953
I believe the issue is that you're missing the }
to close the function in your javascript.
If you turn on your browser's development tools using F12, then this would be obvious for you. I personally recommend FireBug running under FireFox.
As a side note, something you should be aware of with ASP.NET...
If you disable a textbox through ASP.NET (using txtAmount.Enabled = false;
) then the value in the textbox will always be the original value on the post-back. It doesn't matter whether you enable the textbox on the client, ASP.NET knows it was original disabled, so it keeps it disabled.
In order to bring back the value, I would recommend you also have a <asp:HiddenField>
control, an update the value in that whenever you change the textbox. Then use the value of the hidden field on your post-back.
Upvotes: 2