10
Reply

Javascript enable/disable button based on text in textboxes

aiswarjya sarengi

aiswarjya sarengi

Feb 25 2016 6:50 AM
524
<script language="javascript" type="text/javascript">
//function to enable button if two textboxes contains text
function SetButtonStatus(sender, target) {
var first = document.getElementById('<%=txtfirst.ClientID %>');
var second = document.getElementById('<%=txtText.ClientID %>');
//Condition to check whether user enters text in two textboxes or not
if ((sender.value.length >= 1 && first.value.length >= 1) && (sender.value.length >= 1 && second.value.length >= 1))
document.getElementById(target).disabled = false;
else
document.getElementById(target).disabled = true;
}
</script>

<div> <asp:TextBox ID="txtfirst" runat="server" onkeyup="SetButtonStatus(this,'btnButton')"></asp:TextBox> <asp:TextBox ID="txtText" runat="server" onkeyup="SetButtonStatus(this,'btnButton')"></asp:TextBox> <asp:Button ID="btnButton" runat="server" Text="Button" Enabled="false" /> </div>



but its throws an error

the error is:


The Controls collection cannot be modified because the control contains code blocks



Answers (10)