Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi to all,
i want to appear and disappear the button,while typing the text in text-box.
don't do any other functionality in page-load or refresh the page just type the text the button should appear,if the text box should empty then button disappear.Kindly help for this task.
Posted

Use the following JavaScript code. Wrap it in a <script> tag and place it on your <head> tag:
JavaScript
window.onload = function () {
    var txt = document.getElementById("<%= yourTxt.ClientID %>");
    var btn = document.getElementById("<%= yourBtn.ClientID %>");
    if (txt.value === "") {
        btn.style.visibility = "hidden";
        // when the window is loaded, hide the button if the textbox is empty
    }
    txt.onkeyup = function () {
        if (txt.value !== "") {
            btn.style.visibility = "visible";
        } else {
            btn.style.visibility = "hidden";
        }
    };
};

When your page is loaded, it checks whether the textbox is empty, and if it is, it hides the button.

At onkeyup, the code checks whether there's text in the textbox. If yes, it shows the button, if no, it hides the button.
 
Share this answer
 
v4
Comments
JOTHI KUMAR Member 10918227 17-Feb-15 8:45am    
how to use this code explain me briefly
Thomas Daniels 17-Feb-15 8:47am    
Wrap the JavaScript code in a <script>-tag and put the script-tag in your head-tag.
JOTHI KUMAR Member 10918227 17-Feb-15 8:48am    
hmm ok then next step??
Thomas Daniels 17-Feb-15 8:50am    
Then make your Button invisible by default (see step 1 in my answer), and then you're ready.
JOTHI KUMAR Member 10918227 17-Feb-15 8:50am    
any change in design or anythink .
C#
function EnableDisableButton(sender, target) {
         if (sender.value.length > 0)
             document.getElementById('<%= btnReset.ClientID %>').disabled = false;
             else
                 document.getElementById('<%= btnReset.ClientID %>').disabled = true;
         }
 
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