Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want---if we have enter a value in textbox the button sholud be displayed other wise it disable


What I have tried:

i want---if we have enter a value in textbox the button sholud be displayed other wise it disable
Posted
Updated 20-Mar-17 20:08pm
v2

<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
    <script>
        function funblur(txt) {
            var flag = (txt.value == '');
            document.getElementById('<%= btn.ClientID %>').style.display = flag ? 'none' : 'block';
        } 

    </script>
</head>
<body>
    <form id="form1" runat="server">
        
        <asp:TextBox ID="txt" runat="server" onblur="funblur(this)"></asp:TextBox>
        <asp:Button ID="btn" runat="server"   />
    </form>
</body>
</html>
 
Share this answer
 
There can be multiple solution for it. we have onKeyUp onKeyDown events for textbox. all you have to do is check if textbox is empty. if so then disable the button else enable the button.

<input type="text" id="txtSomeTextbox">
<input type="button" id="txtSomeButton">

$(document).ready(function() {
     $('#txtSomeButton').prop('disabled', true);
     $('#txtSomeTextbox').keyup(function() {
        if($(this).val() != '') {
           $('#txtSomeButton').prop('disabled', false);
        }
     });
 });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900