Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to show a button if the text box is not empty.

What I have tried:

Otherwise empty the textbox value, then hide button like toggle in jQuery. How can I do this? here is fiddle...
[^]
Posted
Updated 23-Apr-17 2:06am
v4

1 solution

Perhaps the following function would work,
JavaScript
$("#txtBoxClientId").change(function () { // Your keyup function was also correct
    if($(this).val() == "") {
        // If text is empty, 
        $("#btnId").hide();
    } else {
        // Text found
        $("#btnId").show();
    }
});

This would also let you make a condition to only show button when there are a few characters in the textbox.

The problem at that location can be answered in different ways,

1. The jQuery may not be loaded. If you open the External libraries tab, you will see you did not include anything.
2. JSFiddle writes all of the content in a nested HTML document, thus you cannot easily map the functions in there. Write a sample HTML document in your notepad, and then write the code as well. Run that file in any browser to get a good demo.
 
Share this answer
 
Comments
Member 12955507 23-Apr-17 8:25am    
Thank a lot... and I will keep in mind

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