JQuery: make a button visible when a TextBox contains content

Given: I have a text box and a hidden button.

Required: If the text field is neither empty nor empty, show the button. If the text box is blank or empty, hide the button.

Question: How do I do this? Should I use jQuery and bind to a keyup keybox event?

+6
jquery visibility events button textbox
source share
1 answer

Of course, the keyup event sounds like a great idea. You can do something like:

 $("textarea").keyup(function() { if ($(this).val().replace(/ /g, '') == '') $("#id-of-button").show(); else $("#id-of-button").hide(); }); 
+13
source share

All Articles